Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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()
Source by www.dataquest.io #
 
PREVIOUS NEXT
Tagged: #Add #column #based #condition #column
ADD COMMENT
Topic
Name
3+2 =