pandas new column based on another column value code example
Example 1: change column value based on another column pandas
df['is_electric']= df['type'].apply(lambda x: 'YES' if (x == 'electric') else 'NO')
Example 2: pandas create new column conditional on other columns
conditions = [
(df['Base Column 1'] == 'A') & (df['Base Column 2'] == 'B'),
(df['Base Column 3'] == 'C')]
choices = ['Conditional Value 1', 'Conditional Value 2']
df['New Column'] = np.select(conditions, choices, default='Conditional Value 1')