vendredi 26 février 2021

Merging two dateframes based on condition

I have 2 dataframes data1 and data2 that I want to join. I want to keep 3 columns from data2

The condition that I need is that if the column 'col1' in data2 has nan values then the key for joining the datasets would be col1, col2 and col3. Else the key for joining would be col1 and col3 only.

I tried writing a function based on if-else statements but it does not seem to work

Any help would be appreciated

Aucun commentaire:

Enregistrer un commentaire