I have two dataframes and I want to merge them using 2 keys and one of them will be columns directly
I have the following Dataframes:
DF:-
Sex Age Height country Year Grade
0 M 31.0 188.0 Bulgaria 2016 D+
1 F 28.0 166.0 China 1996 D+
2 M 30.0 NaN Sweden 1960 D+
3 F 28.0 181.0 China 2004 D+
4 F 16.0 175.0 Hungary 1998 D+
GDP_data:
Country Name Country Code 2016 1996 1960 2004 1998
0 Bulgaria BGR 1946 NaN 5377 5285 NaN
1 China CHI 1186 3314 NaN 7314 3314
2 Sweden SWE 1590 4694 2723 8532 4694
3 China CHI 6580 NaN NaN 5120 NaN
4 Hungary HUN 2858 1223 NaN 2935 1223
The desired Dataframe after merge is:-
Sex Age Height country Year Grade GDP
0 M 31.0 188.0 Bulgaria 2016 D+ 1946
1 F 28.0 166.0 China 1996 D+ 3314
2 M 30.0 NaN Sweden 1960 D+ 2723
3 F 28.0 181.0 China 2004 D+ 5120
4 F 16.0 175.0 Hungary 1998 D+ 1223
The resultant DataFrame should get the GDP of country with respect to year.
I need to match Country Name and country from DF and GDP_data respectively and also Year column from first DataFrame but in the second DataFrame I have years as columns.
How do I merge these two?
This is just the sample Data I have shown here but in reality it is very big data with arount 20000 rows and gdp data from 1960 to 2016. But the Idea should be the same.
1996?meltfunction