datascienceschool / book

23 stars 23 forks source link

01%20python/04.08%20%EC%8B%9C%EA%B3%84%EC%97%B4%20%EC%9E%90%EB%A3%8C%20%EB%8B%A4%EB%A3%A8%EA%B8%B0 #60

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

4.8 시계열 자료 다루기 — 데이터 사이언스 스쿨

http://datascienceschool.net/01%20python/04.08%20%EC%8B%9C%EA%B3%84%EC%97%B4%20%EC%9E%90%EB%A3%8C%20%EB%8B%A4%EB%A3%A8%EA%B8%B0.html

byeongtaejeon commented 2 years ago

4.8.1

s = df["date"].squeeze() df_m = s.dt.month.to_frame() df_m.rename(columns={'date':'month'}, inplace=True)

df_m

df2 = pd.concat([df, df_m], axis=1)

df2

df2.value.groupby(df2.month).sum()

lacking-in-thought commented 2 years ago

np.random.seed(0) df=pd.DataFrame({ 'date': pd.date_range('2020-12-25',periods=100,freq='D'), 'value': np.random.randint(100,size=(100,))}) df.set_index('date') df['month']=df['date'].dt.month df.groupby('month')['value'].sum()

CreatorHun commented 2 years ago

df.groupby(df["date"].dt.month).sum()

Jeon-doun commented 5 months ago

df.groupby(df.date.dt.month).value.sum()