I'm new to Python. I have the below code:
import wbdata # World Bank's API
import pandas
import matplotlib.pyplot as plt
#countries I want
countries = ["CL","UY","HU"]
#indicators I want
indicators = {'NY.GNP.PCAP.CD':'GNI per Capita'}
#grab indicators above for countries I want and load into data frame
df = wbdata.get_dataframe(indicators, country=countries, convert_date=False)
#list the columns in data frame
list(df.columns.values)
The output for my data frame and the number of columns in the data frame is the following:
In [1]:df
Out[1]:
GNI
country date
Chile 2017 13610.0
2016 13430.0
2015 14270.0
2014 15140.0
2013 15360.0
2012 14410.0
2011 12380.0
...
Uruguay 2017 23410.0
2016 11430.0
2015 11270.0
2014 11440.0
2013 65360.0
2012 94410.0
2011 10380.0
[174 rows x 1 columns]
In [2]: list(df.columns.values)
Out[2]: ['GNI']
As you see, only one of the columns in the data frame ("GNI") is recognized as a column.
What can I do to have 'country' and 'date' be recognized as columns as well?
My objective is to have a panel dataset of the type seen below. Where there are three variables (=Stata language): Country, Date and GNI. And where no blanks exist in the Country variable, as each GNI observation corresponds to a country-date combination.
Country Date GNI
Chile 2017 13610.0
Chile 2016 13430.0
Chile 2015 14270.0
Chile 2014 15140.0
Chile 2013 15360.0
Chile 2012 14410.0
Chile 2011 12380.0
...
Uruguay 2017 23410.0
Uruguay 2016 11430.0
Uruguay 2015 11270.0
Uruguay 2014 11440.0
Uruguay 2013 65360.0
Uruguay 2012 94410.0
Uruguay 2011 10380.0
[174 rows × 3 columns]
Surely I'm butchering the Python syntax and language, but any help or guidance would be appreciated.