可能我的例子是很多大,我的代码是在这里:如何获取自定义时间间隔中的最后日期? - 熊猫
import pandas as pd
import numpy as np
import io
t = """
name date
a 2005-08-31
a 2005-09-20
a 2005-11-12
a 2005-12-31
a 2006-03-31
a 2006-06-25
a 2006-07-23
a 2006-09-28
a 2006-12-21
a 2006-12-27
a 2007-07-23
a 2007-09-21
a 2007-03-15
a 2008-04-12
a 2008-06-21
a 2008-06-11
b 2005-08-31
b 2005-09-23
b 2005-11-12
b 2005-12-31
b 2006-03-31
b 2006-06-25
b 2006-07-23
b 2006-09-28
b 2006-12-21
b 2006-12-27
b 2007-07-23
b 2007-09-21
b 2007-03-15
b 2008-04-12
b 2008-06-21
b 2008-06-11
"""
data=pd.read_csv(io.StringIO(t),delimiter=' ')#5 space here
data
我想要做的是找到哪一年开始2005-7-1
一年的天和最后一天),并最终2006-06-30
,开始2006-7-1
并结束2007-6-30
...等等。 我的预期输出是在这里:
name date
a 2006-06-25 #the last day of the 2005/7/01 -2006/06/31
a 2007-03-15 #the last day of the 2006/7/01 -2007/06/31
a 2008-06-21 #the last day of the 2007/7/01 -2008/06/31
b 2006-06-25 #the last day of the 2005/7/01 -2006/06/31
b 2007-03-15 #the last day of the 2006/7/01 -2007/06/31
b 2008-06-21 #the last day of the 2007/7/01 -2008/06/31
怎样才能解决这个问题?我想我应该使用custom
是是长期看? – ileadall42
注意:9月只有30天,所以有一些不好的数据。 –
@AndyHayden我的天啊,多亏了点! – ileadall42