gyr*_*yre 2 python plot matplotlib pandas
我有以下数据框:
Joined User ID
0 2017-08-19 user 182737081
1 2017-05-07 user 227151009
2 2017-11-29 user 227306568
3 2016-05-22 user 13661634
4 2017-01-23 user 220545735
Run Code Online (Sandbox Code Playgroud)
我正在尝试弄清楚如何绘制用户随时间的增长情况。我认为最好的方法是绘制累计和。我整理了一个简单的代码:
tmp = members[['Joined']].copy()
tmp['count'] = 1
tmp.set_index('Joined', inplace=True)
Run Code Online (Sandbox Code Playgroud)
这将产生以下结果cumsum
:
count
Joined
2017-08-19 1
2017-05-07 2
2017-11-29 3
2016-05-22 4
2017-01-23 5
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试使用它绘制图时,tmp.plot()
我会得到如下所示的超级奇怪的信息,呃:
我使用的熊猫版本: pandas (0.20.3)
如果您想知道序列的长度是否与最高计数相同:
tmp.cumsum().max() == len(tmp)
count True
dtype: bool
Run Code Online (Sandbox Code Playgroud)
好像您需要sort_index
,然后cumsum
,然后plot
#tmp.index=pd.to_datetime(tmp.index)
tmp.sort_index().cumsum().plot()
Run Code Online (Sandbox Code Playgroud)