Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 访问世界银行数据指标和使用熊猫数据框架_Python_Pandas - Fatal编程技术网

Python 访问世界银行数据指标和使用熊猫数据框架

Python 访问世界银行数据指标和使用熊猫数据框架,python,pandas,Python,Pandas,我正试图访问世界银行的一系列健康指标数据 要访问世界银行数据,请使用以下代码: 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 marri

我正试图访问世界银行的一系列健康指标数据

要访问世界银行数据,请使用以下代码:

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)
进口:

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

我在网上看了一下,但没有发现任何特别有用的东西。

数据帧转换为字典:

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)

您应该调用
wbdata.get_dataframe()
,使用包含
(指示符)和
(说明)的
字典
。现在您正在发送两个
系列
对象。