I have a dataframe:
gp_df = CCA3 Country/Territory year GDP_USD
2662 AFG Afghanistan 1970 1.748887e+09
2661 AFE Africa Eastern and Southern 1970 4.486261e+10
2663 AFW Africa Western and Central 1970 2.350461e+10
2665 ALB Albania 1970 NaN
2720 DZA Algeria 1970 4.863487e+09
... ... ... ... ...
16156 PSE West Bank and Gaza 2020 1.553170e+10
16219 WLD World 2020 8.490680e+13
16222 YEM Yemen, Rep. 2020 1.884051e+10
16224 ZMB Zambia 2020 1.811063e+10
16225 ZWE Zimbabwe 2020 1.805117e+10
I want to create 2 new columns called '1970 gdp' and '2020 gdp' where it takes the 'GDP_USD' value at each year and matches it with the 'country/territory'
Example:
gp_df = CCA3 Country/Territory 1970 GDP 2020 GDP
2662 AFG Afghanistan 1.748887e+09 3.486261e+10
2661 AFE Africa Eastern and Southern 4.486261e+10 7.345261e+10
This is what I've tried so far but it didn't work:
gp_df['1970 GDP'] = np.where(gp_df['year']
== '1970', year_GDP_USD.loc[gp_df.index], 0 )
gp_df['2020 GDP'] = np.where(gp_df['year']
== '2020', 'GDP_USD', 0 )