본문 바로가기

전체 글732

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.
pandas 판다스 기초 5 summer = pd.read_csv('summer.csv', index_col='Athlete') event = summer.Event event.head() # na_position='last'의 의미는 앞에서 어떻게 ascending 이 되든 관계없이 가장 마지막에 결측치 값을 넣는다는 의미다. sales.sort_values(ascending=False, na_position='last', inplace=True) titanic = pd.read_csv('titanic.csv') titanic.head(3) age = titanic.age age ''' 0 22.0 1 38.0 2 26.0 3 35.0 4 35.0 ... 886 27.0 887 19.0 888 NaN 889 26.0 890 32... 2022. 7. 15.