Here's my data on first table
Id City Count
1 New York 445
2 London 543
3 Tokyo 342
4 Jakarta 646
5 Tokyo 454
6 Singapore 340
7 Jakarta 293
8 Tokyo 219
9 Singapore 478
Here's my data on second table
City City_code
New York 1
London 2
Tokyo 3
Jakarta 4
Singapore 5
Then, I try to merge
df_c = pd.merge(df_a, df_b, on="City_code")
df_c
And the result
Id City Count City_code
1 New York 445 1
2 London 543 2
3 Tokyo 342 3
4 Jakarta 646 5
5 Tokyo 454 3
7 Jakarta 293 5
8 Tokyo 219 3
As you can see, the singapore city data is loss during merge, how to handle that?
Notes:
- My Actual dataset is 1568 rows
- when I perform
pd.merge(df_a, df_b, on="City_code", how='outer')
the data being 1570 rows - when I perform
pd.merge(df_a, df_b, on="City_code")
the data being 1546 rows