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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -