분류 전체보기718 pandas (판다스) 기초 8 and, or ## Filtering DataFrames with many Conditions (AND) import pandas as pd titanic = pd.read_csv('titanic.csv') titanic.head() # 남자면서 14살 이상의 사람이 살게된 케이스를 살펴보기위한 필터를 위해서 # 먼저 남자를 지정해준다. mask_male = titanic.sex == 'male' mask_male # 그 다음으로는 14살을 지정해준다. mask_age = titanic.age > 14 mask_age (mask_male & mask_age).head() ''' 0 True 1 False 2 False 3 False 4 True dtype: bool ''' # pandas(판다스) and 조건으로 출력.. 2022. 7. 18. pandas (판다스) 기초 7 filtering # DataFrame Basics II ## Filtering DataFrames with one Condition import pandas as pd titanic = pd.read_csv('titanic.csv') titanic.head() # 이 연산은 백터 연산이 된 것이므로, 반복문이 필요 없다. titanic.sex == 'male' ''' 0 True 1 False 2 False 3 False 4 True ... 886 True 887 False 888 False 889 True 890 True Name: sex, Length: 891, dtype: bool ''' # 이 방법은 numpy 와 같은 방법으로써 titanic.sex에서 male 에 속한 값만을 필터링해서 리턴하는 것이다. # .. 2022. 7. 18. pandas 판다스 틀린부분 복기 # 문제 1 # Check whether the new index contains only unique values (no duplicates)! Is this the case? cars.index.is_unique ''' 정답을 그냥 cars 라고 변수명만 입력해주었다. unique values에 대해서 보여주라는 가이드를 해석하지 못했기 때문이다. ''' # 문제 2 # Get the frequency/Counts of all unique values in the index! What is the most frequent value? # 왜 안나올까? frequency 값이 # cars.describe() cars.index.value_counts() ''' 이전에는 describe()로 해겨이 되었.. 2022. 7. 16. pandas 판다스 기초 6 # reset_index()의 기능의 근본은 # 'index_col자리에 index 기준값이 된 것을 해제해준다.'라는 개념같다. # 즉, index_col을 설정해주기 전의 모습으로 돌아가는 것이다. # Pandas Index Objects ## First Steps import pandas as pd summer = pd.read_csv('summer.csv', index_col = 'Athlete') summer.tail() summer.index[0] # 'HAJOS, Alfred' # 모든 인덱스가 고유값인지 판단할 때 쓰이는 함수 (중복되지 않은 인덱스인지 확인) summer.index.is_unique # False summer.index.get_loc('DRIVAS, Dimitrios').. 2022. 7. 16. 이전 1 ··· 104 105 106 107 108 109 110 ··· 180 다음