0

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
Ryan Reid
  • 41
  • 1
  • 10

2 Answers2

2

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
DjaouadNM
  • 22,013
  • 4
  • 33
  • 55
0

df['new_col'] = df['col1'] + df['col2']

Ahmed
  • 120
  • 6