我的数据框如下:
timestamp side price amount fee
0 2018-12-14 13:00:00 buy 0.00338508 5 0.005
1 2018-12-14 13:00:00 buy 0.00337829 5 0.005
2 2018-12-14 14:00:00 buy 0.00338089 5 0.005
3 2018-12-14 14:00:00 buy 0.00338079 1 0.001
4 2018-12-14 15:00:00 sell 0.00338838 8 0.00002711
5 2018-12-14 15:00:00 sell 0.00339132 8 0.00002713
6 2018-12-14 15:00:00 buy 0.00337999 5 0.005
7 2018-12-14 16:00:00 sell 0.00339373 5 0.00001697
我需要做的是创建一个列,该列将对具有相同时间戳的列“ amount”的值求和。因此,对于时间戳2018-12-14 13:00:00
,新列将如下所示:
timestamp side price amount fee sum
0 2018-12-14 13:00:00 buy 0.00338508 5 0.005 10
1 2018-12-14 13:00:00 buy 0.00337829 5 0.005 10
我尝试使用以下代码:df_statistics_hour['traded_volume'] = float(df_statistics_hour['amount'].sum())
,但是在新列的每个单元格中当然有相同的值,关于如何进行操作的任何想法?谢谢!