Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在框架中按日期时间的月份进行聚合?_Python_Pandas_Aggregate - Fatal编程技术网

Python 如何在框架中按日期时间的月份进行聚合?

Python 如何在框架中按日期时间的月份进行聚合?,python,pandas,aggregate,Python,Pandas,Aggregate,我的数据框中有下表: 名字出生 jack 1989-11-17 joe 1988-09-10 ben 1980-10-20 kate 1985-05-15 nichos 1986-07-05 john 1989-11-12 tom 1980-10-25 jason 1985-05-21 eron 1985-07-10 yun 1989-11-05 kung 1986-07-01 我想按出生月份做一些汇总,结果如下: moth cnt 1989-11 3

我的数据框中有下表:

名字出生

jack 1989-11-17

joe  1988-09-10

ben  1980-10-20

kate 1985-05-15

nichos 1986-07-05

john  1989-11-12

tom   1980-10-25

jason 1985-05-21

eron  1985-07-10

yun   1989-11-05

kung  1986-07-01
我想按出生月份做一些汇总,结果如下:

moth cnt

1989-11 3

1988-09 1

1986-07 2

1985-07 1

1985-05 2

1980-10 2
有什么方便的方法吗?
非常感谢

将数据放入TimeSeries对象,然后调用重采样:

s.resample("M", how="count")

将数据放入TimeSeries对象,然后调用重采样:

s.resample("M", how="count")

感谢它的工作,它确实希望datetime作为索引,而不是列,需要
。set_index()
感谢它的工作,它确实希望datetime作为索引,而不是列,需要
。set_index()