Date
列到
datetime
:
df.Date=pd.to_datetime(df.Date,format='%m/%d/%Y')
然后:
m=(df.assign(cum_Amount=df.Amount.cumsum()).
groupby(df.Date.dt.month)['cum_Amount'].max().reset_index())
print(m)
Date cum_Amount
0 9 32029.59
1 10 31063.64
2 11 32596.70
3 12 30630.96
编辑
似乎您已经有余额,您只想筛选月末日期,请使用:
from pandas.tseries.offsets import MonthEnd
df[df.Date.eq(df.Date+MonthEnd(0))]
Date Amount Month Balance
1 2018-09-30 29.59 9 32029.59
3 2018-10-31 -1000.00 10 31063.64
5 2018-11-30 33.06 11 32596.70
7 2018-12-31 34.26 12 30630.96