Answers for "df create new column based on other columns"

1

pandas new column from others

import pandas as pd

#Here a and b are existing columns

df['c'] = df.apply(lambda row: row.a + row.b, axis=1)
df
#    a  b  c
# 0  1  3  4
# 1  2  4  6
Posted by: Guest on May-07-2021

Code answers related to "df create new column based on other columns"

Python Answers by Framework

Browse Popular Code Answers by Language