Quantcast
Channel: How to change a column values from dataframe comparing value from another dataframe only if the new value is not empty? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Varsha Kishore for How to change a column values from dataframe comparing value from another dataframe only if the new value is not empty?

$
0
0

Try this:

df2 = df2.replace(r'^\s*$', np.nan, regex=True)df2 = df2.set_index("patient_id")['email_address'].fillna(df1.set_index('Patient Id')['Email']).reset_index()df1['Email'] = df1['Patient Id'].map(df2.set_index('patient_id')['email_address'])

The first line replaces empty strings with NaN. The second line fills the Nan values in df2 with values from df1. The last line is the same as the line you had.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>