Reputation: 4636
I have the following DataFrame:
Value Seasonal
Date
2004-01-01 0 -10.000000
2004-02-01 173 -50.000000
2004-03-01 225 0.000000
2004-04-01 230 9.000000
I want to sum its items so it gets like this:
Value
Date
2004-01-01 -10.000000
2004-02-01 123.000000
2004-03-01 225.000000
2004-04-01 239.000000
Is there an easy way to do that?
Upvotes: 1
Views: 94
Reputation: 1809
df['Value'] += df['Seasonal']
dfnew = df.drop('Seasonal', axis=1)
print(dfnew)
Output:
Date Value
0 2004-01-01 -10
1 2004-02-01 123
2 2004-03-01 225
3 2004-04-01 239
Upvotes: 0
Reputation: 10493
If you want to create an entirely new data frame without messing up the old one.
import pandas as pd
In [12]: pd.DataFrame({"Date": df["Date"], "Value": df["Value"] + df["Seasonal"]})
Out[12]:
Date Value
0 2004-01-01 -10
1 2004-02-01 123
2 2004-03-01 225
3 2004-04-01 239
Upvotes: 2