본문 바로가기

전체 글732

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.
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.