maptastik
10/9/2019 - 3:04 PM

Calculate a new pandas DataFrame column based on an aggregation of values from other columns's values in a rows

import pandas as pd
df = pd.DataFrame({'a': [1,2,3], 'b': [2,3,4], 'c':['dd','ee','ff'], 'd':[5,9,1]})

df['e'] = df[['a', 'b', 'd']].sum(axis = 1)

#########################
##        RESULT       ##
#########################
#      a  b   c  d   e  # COLUMNS
#   0  1  2  dd  5   8  # ROW
#   1  2  3  ee  9  14  # ROW
#   2  3  4  ff  1   8  # ROW
#########################