示例#1
0
def get_china_yearly_gdp():
    """
    获取中国年度GDP数据, 数据区间从20110120-至今
    :return: pandas.Series
    2011-01-20    9.8
    2011-04-15    9.7
    2011-07-13    9.5
    2011-10-18    9.1
    2012-01-17    8.9
    2012-04-13    8.1
    2012-07-13    7.6
    2012-10-18    7.4
    2013-01-18    7.9
    2013-04-15    7.7
    2013-07-15    7.5
    2013-10-18    7.8
    2014-01-20    7.7
    2014-04-16    7.4
    2014-07-16    7.5
    2014-10-21    7.3
    2015-01-20    7.3
    2015-04-15      7
    2015-07-15      7
    2015-10-19    6.9
    2016-01-19    6.8
    2016-04-15    6.7
    2016-07-15    6.7
    2016-10-19    6.7
    2017-01-20    6.8
    2017-04-17    6.9
    2017-07-17    6.9
    2017-10-19    6.8
    2018-01-18    6.8
    2018-04-17    6.8
    2018-07-16    6.7
    2018-10-19    6.5
    2019-01-21    6.4
    2019-04-17    6.4
    2019-07-15    6.2
    2019-10-18      6
    """
    t = time.time()
    res = requests.get(
        JS_CHINA_GDP_YEARLY_URL.format(
            str(int(round(t * 1000))), str(int(round(t * 1000)) + 90)
        )
    )
    json_data = json.loads(res.text[res.text.find("{") : res.text.rfind("}") + 1])
    date_list = [item["date"] for item in json_data["list"]]
    value_list = [item["datas"]["中国GDP年率报告"] for item in json_data["list"]]
    value_df = pd.DataFrame(value_list)
    value_df.columns = json_data["kinds"]
    value_df.index = pd.to_datetime(date_list)
    temp_df = value_df["今值(%)"]
    temp_df.name = "gdp"
    return temp_df
示例#2
0
def macro_china_gdp_yearly():
    """
    中国年度GDP数据, 数据区间从20110120-至今
    https://datacenter.jin10.com/reportType/dc_chinese_gdp_yoy
    :return: pandas.Series
    """
    t = time.time()
    res = requests.get(
        JS_CHINA_GDP_YEARLY_URL.format(str(int(round(t * 1000))),
                                       str(int(round(t * 1000)) + 90)))
    json_data = json.loads(res.text[res.text.find("{"):res.text.rfind("}") +
                                    1])
    date_list = [item["date"] for item in json_data["list"]]
    value_list = [item["datas"]["中国GDP年率报告"] for item in json_data["list"]]
    value_df = pd.DataFrame(value_list)
    value_df.columns = json_data["kinds"]
    value_df.index = pd.to_datetime(date_list)
    temp_df = value_df["今值(%)"]
    temp_df.name = "gdp"
    return temp_df