【发布时间】:2019-01-04 12:47:06
【问题描述】:
你好我的数据集如下
username switch_state time
abcd sw-off 07:53:15 +05:00
abcd sw-on 07:53:15 +05:00
现在使用这个我需要找到在给定的一天,一天中有多少次开关状态被操纵,即打开或关闭。我的测试代码如下
switch_off=df.loc[df['switch_state']=='sw-off']#only off switches
groupy_result=switch_off.groupby(['time','username']).count()['switch_state'].unstack#grouping the data on the base of time and username and finding the count on a given day. fair enough
这个 groupby 子句的结果为
print(groupy_result)
username abcd
time
05:08:35 3
07:53:15 3
07:58:40 1
现在您可以看到计数在时间列中连接在一起。我需要将它们分开,以便我可以使用 Seaborn 散点图绘制它。我需要有 x 和 y 值,在我的情况下是 x=time,y=count 请帮助我,我该如何绘制此列。
`
【问题讨论】:
标签: python pandas seaborn scatter-plot pandas-groupby