I am looking to add in a column to my data frame in order to sum the total of all values in a respective row
For example:
1 2 Column I Want to Add
4 9 13
7 1 8
I am looking to add in a column to my data frame in order to sum the total of all values in a respective row
For example:
1 2 Column I Want to Add
4 9 13
7 1 8
You can df.sum(axis = 1)
, which will create a new column (not a row):
import pandas as pd
df = pd.DataFrame({1: [4, 7], 2: [9, 1]})
df['COLUMN I Want to Add'] = df.sum(axis = 1)
print(df)
Output:
1 2 COLUMN I Want to Add
0 4 9 13
1 7 1 8