본문 바로가기
개발일지/Pandas

pandas 판다스 틀린부분 복기2

by 개발에정착하고싶다 2022. 7. 18.
320x100
# 문제 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 "mpg" and "name"!
# Save the subset in the variable not_73_74. Fill in the gaps!

# 이건 거의다 적혀있어서 얻어걸린거나 다름없다. 실질적으론 모르겠다.
# 코드를 보면 해석이 "어느정도"되는 수준이다.
not_73_74 = cars.loc[~cars.model_year.isin([73, 74]), ['mpg', 'name']].copy()
# 문제3
# Add the new column "l_per_100km" to the DataFrame cars by calculating 235.21/mpg. Round to 2 decimals. Fill in the gaps!

# 이것도 대부분 써있어서 얻어 걸린것이지, 특히 round를 써주는것에서 헤멨을것같다.
cars['l_per_100km'] = (235.21/cars.mpg).round(2)
300x250