Answers for "add new column with same value of different columns in df"

3

Add new column based on condition on some other column in pandas.

# np.where(condition, value if condition is true, value if condition is false)

df['hasimage'] = np.where(df['photos']!= '[]', True, False)
df.head()
Posted by: Guest on August-08-2021
0

new column with addition of other columns

df['C'] = df.apply(lambda row: row['A'] + row['B'], axis=1)
Posted by: Guest on September-11-2021

Code answers related to "add new column with same value of different columns in df"

Python Answers by Framework

Browse Popular Code Answers by Language