Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

change column value based on another column pandas

# Changes the 'is_electric' column based on value in the 'type' column
# If the 'type' column == 'electric' then the 'is_electric' becomes 'YES'
df['is_electric']= df['type'].apply(lambda x: 'YES' if (x == 'electric') else 'NO') 
Source by pandas.pydata.org #
 
PREVIOUS NEXT
Tagged: #change #column #based #column #pandas
ADD COMMENT
Topic
Name
1+5 =