通过另一列重新采样和求和

时间:2018-08-13 13:35:39

标签: python-3.x pandas

如果列resample1DsellFalse,我希望以sumamount

这是我的数据:

id          date            price   amount      sell
23688927    1472688031000   576.27  0.8         false
23688933    1472688054000   576.26  0.020847    true
23688945    1472688144000   576.27  0.14514252  false
23688949    1472688144000   576.27  0.38154176  false

以下代码正确过滤,我只是无法通过提到的列找出如何sum

df.loc[:, 'timestamp'] = pd.to_datetime(df.loc[:, 'date'], unit='ms')
df.index = df.timestamp
(df['sell'] == 0).resample('1D')

阅读一些应该行之有效的文章,我会收到“找不到列:金额”`

(df['sell'] == 0).resample('1D')['amount'].sum()

1 个答案:

答案 0 :(得分:1)

这有效

INSERT INTO table2 (reg2)
SELECT reg
FROM table1
WHERE table2.ID2 = table1.ID;

输出:

(df[df['sell'] == 0]).resample('1D').amount.sum()