본문 바로가기

분류 전체보기718

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 판다스 틀린부분 복기2 # 문제 1 # Filter the DataFrame cars for all cars with an mpg between 10 and 15 (both ends inclusive!). # Save the subset in the variable mpg_10_15! Fill in the gaps! # between을 활용해야하는데, 기억이 잘 안나더라. 풀기야 했는데 복기용으로 남겨두자. mpg_10_15 = cars.loc[cars.mpg.between(10,15, inclusive=True)].copy() # 문제 2 # Filter the Dataframe cars for all cars that are not built in the years 73 and 74, and only the columns .. 2022. 7. 18.
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 (판다스) 기초9 **중요** filtering with any, all, between, isin, 열, 행 삭제 추가하기 import pandas as pd summer = pd.read_csv('summer.csv') og_1988 = summer.loc[summer.Year == 1988] og_1988.info() ''' Int64Index: 1546 entries, 18051 to 19596 Data columns (total 9 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Year 1546 non-null int64 1 City 1546 non-null object 2 Sport 1546 non-null object 3 Discipline 1546 non-null object 4 Athlete 1546 non-null objec.. 2022. 7. 18.