본문 바로가기

Pandas37

pandas 판다스 rank, unique, nunique, count, 평균, 표준편차(mean, std), 상관계수 corr ## Sorting DataFrame (Version 1.0 Updte) import pandas as pd titanic = pd.read_csv('titanic.csv') titanic.age.sort_values() ''' 803 0.42 755 0.67 644 0.75 469 0.75 78 0.83 ... 859 NaN 863 NaN 868 NaN 878 NaN 888 NaN Name: age, Length: 891, dtype: float64 ''' titanic.sort_values(by = 'age') ''' survivedpclasssexagesibspparchfareembarkeddeck 80313male0.42018.5167CNaN 75512male0.671114.5000SNaN 644.. 2022. 7. 23.
pandas 판다스 기초 11 체인인덱싱(chain indexing) 피하기, copy, 올바른 값 변경해주기 # Manipulating Values in DataFrame ## Best Practise (how you should do it) import pandas as pd titanic = pd.read_csv('titanic.csv') titanic.head() ''' survivedpclasssexagesibspparchfareembarkeddeck 003male22.0107.2500SNaN 111female38.01071.2833CC 213female26.0007.9250SNaN 311female35.01053.1000SC 403male35.0008.0500SNaN ''' ### Changing a single Value (Option 1 with loc) # inplace = True 필요없음 ti.. 2022. 7. 19.
pandas (판다스) 기초 10 세로배열재정의zip, Series, add rows 다중 열 추가 # Series 생성 df2 = pd.Series(index = player, data = nationality, name = 'Nationality').to_frame() df2 ''' Nationality (Argentina, FC Barcelona, False, 1.7, 45)Argentina (Portugal, Juventus FC, False, 1.87, 44)Portugal (Brasil, Paris SG, False, 1.75, 28)Brasil (France, Paris SG, True, 1.78, 21)France (Germany, FC Bayern, True, 1.93, 0)Germany '''​ # Creating DataFrames from Scratch with pd.DataFra.. 2022. 7. 18.
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.