I have the following dataframe df
:
timestamp objectId result
0 2015-11-24 09:00:00 Stress 3
1 2015-11-24 09:00:00 Productivity 0
2 2015-11-24 09:00:00 Abilities 4
3 2015-11-24 09:00:00 Challenge 0
4 2015-11-24 10:00:00 Productivity 87
5 2015-11-24 10:00:00 Abilities 84
6 2015-11-24 10:00:00 Challenge 58
7 2015-11-24 10:00:00 Stress 25
8 2015-11-24 11:00:00 Productivity 93
9 2015-11-24 11:00:00 Abilities 93
10 2015-11-24 11:00:00 Challenge 93
11 2015-11-24 11:00:00 Stress 19
12 2015-11-24 12:00:00 Challenge 90
13 2015-11-24 12:00:00 Abilities 96
14 2015-11-24 12:00:00 Stress 94
15 2015-11-24 12:00:00 Productivity 88
16 2015-11-24 13:00:00 Productivity 12
17 2015-11-24 13:00:00 Challenge 17
18 2015-11-24 13:00:00 Abilities 89
19 2015-11-24 13:00:00 Stress 13
我希望能实现如下所示的条形图,
![Picture taken from here http://pandas.pydata.org/pandas-docs/stable/visualization.html](https://istack.dev59.com/vKg91.webp)
result
列,横轴应该是按照timestamp
列分组的值。标签应该是ObjectID
列中的标签,而非a,b,c,d
。我尝试了几种方法,但都没有成功。最接近的方法是使用plot()
方法,但它不能通过参数进行任何自定义(例如,kind='bar'
不起作用)。groups = df.groupby('objectId')
sgb = groups['result']
sgb.plot()
还有其他想法吗?