Answers for "pandas apply function to column based on another column"

2

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')
Posted by: Guest on November-19-2020
1

python pandas apply function to one column

df['a'] = df['a'].apply(lambda x: x + 1)
Posted by: Guest on April-15-2020

Code answers related to "pandas apply function to column based on another column"

Python Answers by Framework

Browse Popular Code Answers by Language