私はPython 2.7を使用しています。私は私のデータがどのように見えるように、それぞれの説明と月で合計したいPython Pandas合計は日付と説明
raw_data = {'Date': ['12/1/2016', '12/4/2016','12/23/2016', '1/18/2017','1/18/2017','1/19/2017'],
'Account': ['aa1', 'aa2','aa1', 'aa1', 'aa1', 'aa2'],
'Description': ['store1', 'store2','store1', 'store2','store1','store2' ],
'Amount': [26.43, 24.99, 31.54,45.32, 2.00, 15.41],
'Category': ['G','G','G','G','G','G'],
'Initials': ['FR','DB','FR','DB','FR','FR']}
df = pd.DataFrame(raw_data, columns = ['Date','Account','Description','Amount','Category','Initials'])
のように見えるパンダデータフレームを持っている:24.99 store2 2016年12月
日付説明金額
2016年12月store1 57.97
2017年1月には、2017年1月2.00
をstore1
私は月ごとに合計し、以下のコードを書かれているが、私は説明欄を組み込む方法で立ち往生しています60.73をstore2。
#convert Date to datetimeindex
df['Date'] = pd.to_datetime(df['Date'])
df = df.set_index('Date')
#sum by month
df = df.groupby(pd.TimeGrouper("M")).sum()
df
ご指摘いただければ幸いです。ありがとう。