【发布时间】:2022-01-27 22:22:59
【问题描述】:
我有以下数据框:
df=pd.DataFrame(index=[0,1])
df['timestamp'] = ['2022-01-01 20:10:00', '2022-01-01 20:50:00']
df['currency'] = ['USD', 'USD']
df['operation'] = ['deposit', 'deposit']
df['amount'] = [0.1, 0.4]
df:
timestamp currency operation amount
0 2022-01-01 20:10:00 USD deposit 0.1
1 2022-01-01 20:50:00 USD deposit 0.4
如何按小时重新采样数据并将“数量”相加以获得以下数据框:
df:
timestamp currency operation amount
0 2022-01-01 20:00:00 USD deposit 0.5
使用.resample('H') 消除了货币和操作列。我该怎么做才能对“金额”列求和?
【问题讨论】:
标签: python pandas dataframe datetime pandas-resample