Skip to content

Instantly share code, notes, and snippets.

@MuseHorizon
Forked from focaalvarez/vlookup1.py
Last active January 4, 2022 05:36
Show Gist options
  • Save MuseHorizon/e5fa0dfad24c9a7aaa8ad153d05d4ea0 to your computer and use it in GitHub Desktop.
Save MuseHorizon/e5fa0dfad24c9a7aaa8ad153d05d4ea0 to your computer and use it in GitHub Desktop.
Pandas Index Match
# Add only 1 column (City)
table1_city=table1.merge(table2[['Person ID','City']],how='left',on='Person ID')
#Add all columns of table 2 (City and language)
table1_all=table1.merge(table2,how='left',on='Person ID')
#One liner to fill Nans
table1_fill_nans=table1.merge(table2[['Person ID','City']],how='left',on='Person ID').fillna('Unknown')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment