I am new to pandas and I have googled my problem but did not get any help.
Problem Statement:
When I save final CSV using df.to_csv() after performing cumsum() on one of the column amount, My CSV only showing one column amount but I want all the columns in my final CSV.
Sample Data:
*------------------------------------------------*
|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 |
*------------------------------------------------*
My Code using Jupyter Notebook:
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')
Current Result:
*------*
|amount|
*------*
| 50 |
| 120 |
| 90 |
| 120 |
*------*
Expected Result:
*------------------------------------------------*
|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 |
*------------------------------------------------*
how can I achieve this?