Replace this line with your code
What I expected to happen:
What actually happened:
Replace this line with the output/error
Recall once more that each year contains the same countries. Since the regions are fixed values - the region a country was assigned to in 2015 or 2016 won’t change - we should be able to assign the 2015 or 2016 region to the 2017 row.
In order to do so, we’ll use the following strategy:
- Create a dataframe containing all of the countries and corresponding regions from the
- Use the
pd.merge()function to assign the
REGIONin the dataframe above to the corresponding country in
- The result will have two region columns - the original column with missing values will be named
REGION_x. The updated column without missing values will be named
REGION_y. We’ll drop
REGION_xto eliminate confusion.
I understand that we have same countries then regions will also be same f. Hence, it is easy to fill the missing values for 2017 region in our case. However, i am curious to know what if we have different countries then different regions for each year? Assume again that we have a missing values for 2017 region . How do we proceed in this case?
I tried to explore on this case but i am not able to figure out the solution. Would be really great if someone help me to understand on the same?
Thanks in advance for your help.