python - Pandas: Insert New column to dataframe and populate values within new column based on if then logic -
i have dataframe 2 country descriptions. match, don't.
country desc1 country desc2 1 2 uk 3 uk 4 uk uk
i need 1.) insert column (country desc3) row values populated 2.) rule returns country desc1 if matches country desc2.
df['country desc3'] = \ df['country desc1'].mask(df['country desc1'] != df['country desc2']) df country desc1 country desc2 country desc3 0 1 uk nan 2 uk nan 3 uk uk uk
Comments
Post a Comment