如何按月为日期时间创建 bins 并根据它绘制值?
how to create bins for date time by month and plot value counts on it?
我有 8000 天时间戳类型的列:
2013-09-06 00:00:00
我想创建条形图,但按月分组,也许晚些年。现在我有太多的值(天),它们都变成了情节上的一个黑点:
basic_data['opendate'].value_counts().plot(kind='barh')
我试过这个:
by_month = basic_data['opendate].groupby(pd.Grouper(key='date', freq='M')).sum() #maybe count?
如何在直方图上绘制和创建 bins?
使用Grouper
with key
parameter by opendate
column and then GroupBy.size
:
rng = pd.date_range('2017-04-03', periods=100)
basic_data = pd.DataFrame({'opendate': rng, 'a': range(100)})
print (basic_data)
opendate a
0 2017-04-03 0
1 2017-04-04 1
2 2017-04-05 2
3 2017-04-06 3
4 2017-04-07 4
.. ... ..
95 2017-07-07 95
96 2017-07-08 96
97 2017-07-09 97
98 2017-07-10 98
99 2017-07-11 99
[100 rows x 2 columns]
basic_data.groupby(pd.Grouper(key='opendate', freq='M')).size().plot(kind='barh')
我有 8000 天时间戳类型的列:
2013-09-06 00:00:00
我想创建条形图,但按月分组,也许晚些年。现在我有太多的值(天),它们都变成了情节上的一个黑点:
basic_data['opendate'].value_counts().plot(kind='barh')
我试过这个:
by_month = basic_data['opendate].groupby(pd.Grouper(key='date', freq='M')).sum() #maybe count?
如何在直方图上绘制和创建 bins?
使用Grouper
with key
parameter by opendate
column and then GroupBy.size
:
rng = pd.date_range('2017-04-03', periods=100)
basic_data = pd.DataFrame({'opendate': rng, 'a': range(100)})
print (basic_data)
opendate a
0 2017-04-03 0
1 2017-04-04 1
2 2017-04-05 2
3 2017-04-06 3
4 2017-04-07 4
.. ... ..
95 2017-07-07 95
96 2017-07-08 96
97 2017-07-09 97
98 2017-07-10 98
99 2017-07-11 99
[100 rows x 2 columns]
basic_data.groupby(pd.Grouper(key='opendate', freq='M')).size().plot(kind='barh')