dimanche 23 mai 2021

Merge two dataset in Python with hierarchical conditions

I am very new to Python and I was trying to merge two tables using pandas with certain conditions

The first table may look like below

Table 1

ID Name
1 Jane
2 John
3 Mark
4 Andy

The second table may look like below

Table 2

ID status_code
1 1
1 2
2 1
3 2

The output table that I am trying to make will be the one in below

** Output Table **

ID Name status_code
1 Jane 1
2 John 1
3 Mark 2
4 Andy 3

So people like Jane who has both 1 and 2 for 'status_code' in second table, I want to use 1 instead of 2 for that column. And for people like Andy who does not have any code in second table, I want to put 3 instead of NA.

I would really appreciate help for this Thank you

Aucun commentaire:

Enregistrer un commentaire