我的数据集包含天和小时的数据
time slot hr_slot location_point
2019-01-21 00:00:00 0 34
2019-01-21 01:00:00 1 564
2019-01-21 02:00:00 2 448
2019-01-21 03:00:00 3 46
.
.
.
.
2019-01-22 23:00:00 23 78
2019-01-22 00:00:00 0 34
2019-01-22 01:00:00 1 165
2019-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....)
考虑先旋转数据:
# Create normalized date column
df['date'] = df['time slot'].dt.date
# Pivot
df.pivot(index='hr_slot', columns='date', values='location_point').plot()
替代方法改为使用 pandas.crosstab
:
(pd.crosstab(df['hr_slot'],
df['time slot'].dt.date,
values=df['location_point'],
aggfunc='sum')
.plot())