Answers for "add new columns in dataframe based on values of other column"

1

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
1

how to add coloumn based on other column

metadata['class_pnemonia'] = metadata['class'].astype('category').map({0: 'HEALTHY ', 1: 'PNEUMONIA'})
Posted by: Guest on August-09-2021

Code answers related to "add new columns in dataframe based on values of other column"

Python Answers by Framework

Browse Popular Code Answers by Language