[英]How can I plot my groupby() result?
I'm running a groupby()
on my data like this: 我在我的数据上运行
groupby()
,如下所示:
user.groupby(["DOC_ACC_DT", "DOC_ACTV_CD"]).agg("sum")["SUM_DOC_CNT"]
which results in this grouped data: 得出以下分组数据:
DOC_ACC_DT DOC_ACTV_CD
2015-07-01 BR 1
PT 1
2015-07-02 BR 1
PT 1
2015-07-06 BR 1
PT 1
2015-07-08 BR 1
2015-07-09 AD 2
PT 1
2015-07-13 AD 50
BR 52
PT 1
2015-07-14 AD 6
BR 5
PT 1
2015-07-16 BR 1
PT 1
2015-07-23 AD 13
BR 14
PT 3
2015-07-27 BR 1
PT 1
What I want to do now is simply plot by DOC_ACTV_CD
. 我现在想做的只是通过
DOC_ACTV_CD
。 Please not that there are gaps between days so I'd have to fill in zero-values between days where nothing happened eg 请不要在两天之间存在间隙,所以我必须在两天之间没有任何反应的情况下填写零值,例如
2015-07-23 AD 13
BR 14
PT 3
2015-07-25 BR 1
PT 1
would have to become 将不得不成为
2015-07-23 AD 13
BR 14
PT 3
2015-07-24 AD 0
BR 0
PT 0
2015-07-25 AD 0
BR 1
PT 1
before I plot a time series for AD
, BR
and PT
in one plot. 在我在一个图中绘制
AD
, BR
和PT
的时间序列之前。 What's the quickest way to do this? 最快的方法是什么?
You can use: 您可以使用:
df = user.groupby(["DOC_ACC_DT", "DOC_ACTV_CD"]).agg("sum")["SUM_DOC_CNT"]
df.unstack().resample('D').replace(np.nan,0).plot()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.