sns.load_dataset("taxis")
Parameters
- key : str, defaults to None
Groupby key, which selects the grouping column of the target.- freq : str / frequency object, defaults to None
This will groupby the specified frequency if the target selection (via key or level) is a datetime-like object.
df_g = df.groupby([pd.Grouper(key='pickup_time',freq='2H')]
)["passengers", "distance", "fare", "tip", "tolls", "total"
].agg('mean')
df_g
참고 블로그 : https://kkiho.tistory.com/42
# 2019년 3월 23일 데이터만 가져오기
taxis_means = df_g['2019-03-23 06:00:00':'2019-03-23 22:00:00']
taxis_means
# 방법1
df_g[df_g.index.astype(str).str.contains("2019-03-23")]
# 방법2
idx = pd.IndexSlice
df_slice = df_g.loc[idx['2019-03-23 06:00:00':'2019-03-23 22:00:00'],:]
df_slice
참고 https://rfriend.tistory.com/503, https://seong6496.tistory.com/88
df_bor = df.set_index("pickup_borough")
df_bor.index.value_counts().plot.bar(rot=0, figsize=(5,3))