Pandas and sum and cum sum in same dataframe
pandas, python
Solution
Maybe you want this?
In [20]: df['asq_cum']=df['asq'].cumsum()
In [21]: df
Out[21]:
asq asq_cum
asp
0 20 20
1 20 40
Problem
I use the below to create a sum and a cumsum. But they are in two separate dataframes. I want all in one ``` asp = np.array(np.array([0,0,1])) asq = np.array(np.array([10,10,20])) columns=['asp'] df = pd.DataFrame(asp, index=None, columns=columns) df['asq'] = asq df = df.groupby(by=['asp']).sum() dfcum =df.cumsum() ``` How do I have both the sum and the cumsum in the same dataframe. Totally not clear how to do this. Below is what I want ``` asqsum cumsum asp 0 20 20 1 20 40 ```