You can make use of the pd.merge
function
Example: You have a "country" df with "country", "city" and "zip" columns and "continent" df with "country" and "continent" columns. Use the pd.merge function on the common column "country"
country = pd.DataFrame([['country1','city1','zip1'],['country1','city1','zip2'],['country1','city2','zip3'],['country1','city2','zip4'],
['country2','city3','zip5'],['country2','city3','zip6'],['country2','city4','zip7'],
['country3','city5','zip8'],['country3','city6','zip9']],
columns=['country','city','zipcode'])
continent = pd.DataFrame([['country1','A'],['country2','B'],['country3','C'],['country4','D'],['country5','E']],
columns=['country','continent'])
country = country.merge(continent, on=['country'])
print(country)
Output:
country city zipcode continent
0 country1 city1 zip1 A
1 country1 city1 zip2 A
2 country1 city2 zip3 A
3 country1 city2 zip4 A
4 country2 city3 zip5 B
5 country2 city3 zip6 B
6 country2 city4 zip7 B
7 country3 city5 zip8 C
8 country3 city6 zip9 C