Make new column in Panda dataframe by adding values from other columns Make new column in Panda dataframe by adding values from other columns pandas pandas

Make new column in Panda dataframe by adding values from other columns


Very simple:

df['C'] = df['A'] + df['B']


Building a little more on Anton's answer, you can add all the columns like this:

df['sum'] = df[list(df.columns)].sum(axis=1)


The simplest way would be to use DeepSpace answer. However, if you really want to use an anonymous function you can use apply:

df['C'] = df.apply(lambda row: row['A'] + row['B'], axis=1)