I have a table which gives me the gpi score for a country by year.
EXISTING DATA IN THE FINAL DATAFRAME I HAVE:
gpi_year gpi_rank gpi_country gpi_score
2018 1 Iceland 1.096
2018 2 New Zealand 1.192
2018 3 Austria 1.274
.
.
.
2018 161 South Sudan 3.508
2018 162 Afghanistan 3.585
2018 163 Syria 3.6
However, I need to add a date range for each individual row.
Example:
I will check if the row has 2018 if yes then i would duplicate the record for that country for each date starting from 1st Jan 2018 to 31st Dec 2018 (because it is 2018). i.e 365 dates for one single country.
Similarly if the row has the data for 2017 for any country then i need to duplicate the record for that country for each date starting from 1st Jan 2017 to 31st Dec 2017 i.e 365 dates for one single country.
Example: NEED A SIMILAR OUTPUT:
gpi_year gpi_rank gpi_country gpi_score date
2018 1 Iceland 1.096 01-01-2018
2018 1 Iceland 1.096 02-01-2018
2018 1 Iceland 1.096 03-01-2018
.
.
.
.
2018 1 Iceland 1.096 29-12-2018
2018 1 Iceland 1.096 30-12-2018
2018 1 Iceland 1.096 31-12-2018
2018 2 New Zealand 1.096 01-01-2018
2018 2 New Zealand 1.096 02-01-2018
2018 2 New Zealand 1.096 03-01-2018
.
.
.
.
2018 2 New Zealand 1.096 29-12-2018
2018 2 New Zealand 1.096 30-12-2018
2018 2 New Zealand 1.096 31-12-2018
NOTE: My data has 163 countries. Each country has the score for 2017 and 2018.
Therefore for each country i need to assign dates ranging from 1st Jan 2017 to 31st Jan 2017 and 1st Jan 2018 to 31st Jan 2018.