Skip to content

Instantly share code, notes, and snippets.

@MuseHorizon
MuseHorizon / pandas_index_match.py
Last active January 4, 2022 05:36 — forked from focaalvarez/vlookup1.py
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')