我是熊猫的新手,我已经谷歌了我的问题,但没有得到任何帮助。
问题陈述:当我在其中一列上执行后保存最终的CSV时,我的CSV只显示一列,但我希望所有列都在我的最终CSV中。df.to_csv()cumsum()amountamount
示例数据:
*------------------------------------------------*
|effective_date | account_id | currency | amount |
*------------------------------------------------*
| 12/26/19 1 USD 50 |
| 12/27/19 1 USD 70 |
| 11/06/19 2 USD 90 |
| 11/07/19 2 USD 30 |
*------------------------------------------------*
使用Jupyter Notebook的My Code:
import pandas as pd
df = pd.read_csv('payments.csv', index_col=0)
df['effective_when'] = pd.to_datetime(df['effective_when'])
df = df.groupby(['account_id', 'currency', 'effective_date']).sum().groupby(level=[0]).cumsum()
df.to_csv ('cumulativePayments.csv')
当前结果:
*------*
|amount|
*------*
| 50 |
| 120 |
| 90 |
| 120 |
*------*
预期成果:
*------------------------------------------------*
|effective_date | account_id | currency | amount |
*------------------------------------------------*
| 12/26/19 1 USD 50 |
| 12/27/19 1 USD 120 |
| 11/06/19 2 USD 90 |
| 11/07/19 2 USD 120 |
*------------------------------------------------*
我怎样才能做到这一点?
冉冉说
相关分类