多个数据序列的多元时间序列分析

时间:2019-03-20 02:56:13

标签: python machine-learning time-series

我正在遵循本指南中的数据。 https://machinelearningmastery.com/multivariate-time-series-forecasting-lstms-keras/

我有世界银行的数据,从1990年到今天有15个特征,但是我有多个国家的时间序列。当时间序列较长时,以上指南适用。我应该如何“编译”来自不同国家/地区的数据,而这些国家/地区的数据仍具有相同的时间以及在哪里查看?

最佳

import wbdata #pip install wbdata
indicators1 = {"EN.CLC.MDAT.ZS": "Droughts, floods, extreme temperatures (% of population, average 1990-2009)",
          "EN.ATM.CO2E.PP.GD":"CO2 emissions (kg per 2011 PPP $ of GDP)",
          "NY.GDP.PCAP.PP.KD": "GDP",
          "SP.POP.TOTL":"Total Population" ,
          "SP.POP.1564.TO.ZS":"16-64 age % Percentage of population",
          "LP.LPI.INFR.XQ":"Logistics performance index: Quality of trade and transport-related infrastructure (1=low to 5=high)",
          "EG.USE.COMM.FO.ZS":"Fossil fuel energy consumption (% of total)",
          "EG.FEC.RNEW.ZS":"Renewable energy consumption (% of total final energy consumption)",
          "EG.IMP.CONS.ZS":"Energy imports, net (% of energy use)",
          "EN.ATM.METH.KT.CE":"Methane emissions (kt of CO2 equivalent)",
          "EN.ATM.CO2E.KT":"CO2 emissions (kt)",
          "AG.LND.FRST.ZS":"Forest area (% of land area)",
          "EN.ATM.GHGT.KT.CE":"Total greenhouse gas emissions (kt of CO2 equivalent)",
          "NE.IMP.GNFS.ZS":"Imports of goods and services (% of GDP)",
          "NV.AGR.TOTL.ZS":"Agriculture, forestry, and fishing, value added (% of GDP)",
          "NE.EXP.GNFS.ZS":"Exports of goods and services (% of GDP)",
          "NY.GDP.PCAP.PP.CD":"GDP per capita, PPP (current international $)",
          "EN.ATM.NOXE.KT.CE":"Nitrous oxide emissions (thousand metric tons of CO2 equivalent)"

          }

# Store data in pandas. This  will download all requested idicators, for all     countries
df2 = wbdata.get_dataframe(indicators1, country='all', convert_date=True)

1 个答案:

答案 0 :(得分:0)

country_info  = wbdata.get_country(display=False)
data = {}
for i in range(len(country_info)):
    country_id = country_info[i]['id']
    try:
        df = wbdata.get_dataframe(indicators1, country=country_id)
        print ("Retrieved {0} record for country {1}".format(len(df), country_id))
        data[country_id] = df
        except:
            print ("No records for country {0}".format(country_id)) 
  • 获取所有国家/地区代码
  • 按国家/地区级别阅读信息,并将其推送到数据字典中

您还可以创建您感兴趣的所有国家/地区ID的列表,并将其在一次调用中传递给get_dataframe