我正试图获取世界银行的一系列健康指标的数据。
为了访问世界银行的数据,使用了以下代码:
进口:
import wbdata
import datetime见不同指标:
wbdata.get_indicator(source=16) #Source 16 gives indicators for health.这将返回以下内容:
SP.DYN.TFRT.IN Fertility rate, total (births per woman)
SP.DYN.SMAM.MA Mean age at first marriage, male
SP.DYN.SMAM.FE Mean age at first marriage, female若要在一段时间内访问特定国家的数据,请使用以下代码:
data_dates = (datetime.datetime(2015,1,1), datetime.datetime(2015,1,1))
top_20_data = wbdata.get_dataframe({'SP.DYN.TFRT.IN':'Fertility rate, total (births per woman)','SP.DYN.SMAM.MA':'Mean age at first marriage, male'},
country=('BE','BG','CZ','DK','DE','EE','IE','GR','ES','FR','HR','IT','CY','LV','LT','LU',
'HU','MT','NL','AT','PL','PT','RO','SI','SK','FI','SE','GBR'),
data_date=data_dates,
convert_date=False, keep_levels=True)我想要做的是把每个指标输入到数据框架和每个描述中。
我想要做的是创建一个小样本熊猫数据框架:
data = {'Indicator': ['SP.DYN.TFRT.IN', 'SP.DYN.SMAM.MA', 'SP.DYN.SMAM.MA'],
'Description': ['Fertility rate, total (births per woman)', 'Mean age at first marriage, male', 'Mean age at first marriage, female']}
df = pd.DataFrame(data, columns=['Indicator', 'Description']) 然后像这样把这个传递给wdata.get_daframe:
top_20_data = wbdata.get_dataframe({df['Indicator']:df['Description']},
country=('BE','BG','CZ','DK','DE','EE','IE','GR','ES','FR','HR','IT','CY','LV','LT','LU',
'HU','MT','NL','AT','PL','PT','RO','SI','SK','FI','SE','GBR'),
data_date=data_dates,
convert_date=False, keep_levels=True)但我收到以下错误:
TypeError: 'Series' objects are mutable, thus they cannot be hashed我在网上看了一下,但没有发现任何特别有用的东西。
发布于 2018-10-19 11:14:42
将DataFrame转换为字典:
d = dict(df.values)
#another solution
#d = df.set_index('Indicator')['Description'].to_dict()
top_20_data = wbdata.get_dataframe(d,
country=('BE','BG','CZ','DK','DE','EE','IE','GR','ES','FR','HR','IT','CY','LV','LT','LU',
'HU','MT','NL','AT','PL','PT','RO','SI','SK','FI','SE','GBR'),
data_date=data_dates,
convert_date=False, keep_levels=True)https://stackoverflow.com/questions/52891100
复制相似问题