我的數據集包含days和hrs的數據time slot hr_slot location_point2019-01-21 00:00:00 0 342019-01-21 01:00:00 1 5642019-01-21 02:00:00 2 448 2019-01-21 03:00:00 3 46....2019-01-22 23:00:00 23 782019-01-22 00:00:00 0 342019-01-22 01:00:00 1 1652019-01-22 02:00:00 2 65 2019-01-22 03:00:00 3 156....2019-01-22 23:00:00 23 78數據集持續 7 天。即 7*24 行。如何繪制上述數據集的圖形。hr_slot on the X axis : (0-23 hours)loaction_point on Y axis : (location_point)and each day should have different color on the graph: (Day1: color1, Day2:color2....)
1 回答

www說
TA貢獻1775條經驗 獲得超8個贊
考慮旋轉第一您的數據:
# Create normalized date column
df['date'] = df['time slot'].dt.date.astype(str)
# Pivot
piv = df.pivot(index='hr_slot', columns='date', values='location_point')
piv.plot()
更新
要過濾繪制的日期,請使用loc或iloc:
# Exclude first and last day
piv.iloc[:, 1:-1].plot()
# Include specific dates only
piv.loc[:, ['2019-01-21', '2019-01-22']].plot()
使用替代方法pandas.crosstab:
(pd.crosstab(df['hr_slot'],
df['time slot'].dt.date,
values=df['location_point'],
aggfunc='sum')
.plot())
添加回答
舉報
0/150
提交
取消