본문 바로가기

전체 글732

pandas 틀린부분 복기 5 apply, value_counts # 문제1 # Calculate for all numerical columns the range between highest and lowest value! Fill in the gaps! The range for mpg is...? # apply 가 생각이 안났다. # 어차피 답안을 보니깐 틀린듯 하다. 왜 이런 결과가 나왔을까? # 차이가 너무 심하게 난다. # 행 전부에 열은 model_year까지 가져오는 것이고.. # axis가 행을 기준으로 해서 그런건가? # 행을 기준으로하면 확실히 최고값인 weight에서 최소값인 cylinders를 빼면 말이 된다. cars.iloc[:, :-2].apply(lambda x: x.max() - x.min(), axis = 1) cars.iloc[:,:-2.. 2022. 7. 25.
pandas 판다스 기초11 slice, upper, lower, title등 Series의 경우에 작동하는 문법 # 원하는 결과값은 전체 출력이다. # 전체출력은 원래 그냥 변수만 입력해주면 끝나지만, # 다중 인덱스를 슬라이스해서 전체출력을 해주는 것이 유의미 할것같아서 시도해보고 싶었다. # 시도 1 # titanic.loc[(slice(all), slice(all)), :] # TypeError: ' 2022. 7. 25.
pandas 틀린부분 복기 4 # 문제 1 # Sort the cars DataFrame by the index from low to high. Save the order! # index 기준으로 정렬 하는 법을 모르겠다. # cars.sort_values(by = index) # cars.sort_values(by = 'index') # cars.sort_values(by = 'index', axis=1) # cars.sort_values(by = row, axis=1) # 그냥 간단하게 sort_index였다... cars.sort_index(ascending= True, inplace=True) # 틀린건 아니지만 취지에는 틀렸던 것 1 #Select the 10 cars with the highest weights!\ cars.. 2022. 7. 23.
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.