how to add the sum of multiple columns into another column in a dataframe
print(df)
Apples Bananas Grapes Kiwis
02.03.0 NaN 1.011.03.07.0 NaN
2 NaN NaN 2.03.0
df['Fruit Total']=df.iloc[:,-4:].sum(axis=1)print(df)
Apples Bananas Grapes Kiwis Fruit Total
02.03.0 NaN 1.06.011.03.07.0 NaN 11.02 NaN NaN 2.03.05.0
import pandas as pd
df ={'col_1':[0,1,2,3],'col_2':[4,5,6,7]}
df = pd.DataFrame(df)
df[['column_new_1','column_new_2','column_new_3']]=[np.nan,'dogs',3]#thought this wo
df['Fruit Total']= df.iloc[:,-4:-1].sum(axis=1)print(df)
Apples Bananas Grapes Kiwis Fruit Total
02.03.0 NaN 1.05.011.03.07.0 NaN 11.02 NaN NaN 2.03.02.0