samedi 15 juillet 2017

Python Data frame: Create New Column that Conditionally Concatenates String Values from 1 or 3 Other Columns

Goal: Create new column that outputs strings based on value in original column

Below is my data frame table. I want to create the new column highlighted in yellow.

enter image description here

Below is my business logic:

1. If value in 'Cat_Priority_1' = 'Cat_1' then the new column ('Cat_Priority_1_Rationale') is equal to the string values in 'Age_Flag', 'Salary_Flag', and 'Education_Flag' columns.  
2. If value in 'Cat_Priority_1' = 'Cat_3' then the new column ('Cat_Priority_1_Rationale') is equal to the string values in 'Race_Flag'

This is the code I tried, but it didn't work:

enter image description here

Any help greatly appreciated!

Aucun commentaire:

Enregistrer un commentaire