可能我的例子是很多大,我的代碼是在這裏:如何獲取自定義時間間隔中的最後日期? - 熊貓
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