我覺得你dt.date
或dt.hour
和聚集size
需要groupby
,最後plot
:
df.groupby(df['Date'].dt.date).size().plot()
或者:
#change axis name to Hours by rename
df = df.groupby(df['Date'].rename('Hours').dt.hour).size().plot()
樣品:
rng = pd.date_range('2017-04-03', periods=15, freq='3.5H')
df = pd.DataFrame({'Date': rng})
print (df)
Date
0 2017-04-03 00:00:00
1 2017-04-03 03:30:00
2 2017-04-03 07:00:00
3 2017-04-03 10:30:00
4 2017-04-03 14:00:00
5 2017-04-03 17:30:00
6 2017-04-03 21:00:00
7 2017-04-04 00:30:00
8 2017-04-04 04:00:00
9 2017-04-04 07:30:00
10 2017-04-04 11:00:00
11 2017-04-04 14:30:00
12 2017-04-04 18:00:00
13 2017-04-04 21:30:00
14 2017-04-05 01:00:00
print (df.groupby(df['Date'].rename('Hours').dt.hour).size())
Hours
0 2
1 1
3 1
4 1
7 2
10 1
11 1
14 2
17 1
18 1
21 2
dtype: int64
df.groupby(df['Date'].rename('Hours').dt.hour).size().plot()
df.groupby(df['Date'].rename('Hours').dt.hour).size().plot.bar()
你想吧情節? – jezrael
酒吧陰謀作品!線圖也很好。只是試圖看看趨勢/變化率 – Acoustic77