Example #1
0
def get_china_monthly_cpi():
    """
    获取中国月度CPI数据, 数据区间从19960201-至今
    :return: pandas.Series
    1996-02-01     2.1
    1996-03-01     2.3
    1996-04-01     0.6
    1996-05-01     0.7
    1996-06-01    -0.5
                  ...
    2019-07-10    -0.1
    2019-08-09     0.4
    2019-09-10     0.7
    2019-10-15     0.9
    2019-11-09       0
    """
    t = time.time()
    res = requests.get(
        JS_CHINA_CPI_MONTHLY_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"]["中国CPI月率报告"] 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 = "cpi"
    return temp_df
Example #2
0
def macro_china_cpi_monthly():
    """
    中国月度CPI数据, 数据区间从19960201-至今
    https://datacenter.jin10.com/reportType/dc_chinese_cpi_mom
    :return: pandas.Series
    """
    t = time.time()
    res = requests.get(
        JS_CHINA_CPI_MONTHLY_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"]["中国CPI月率报告"] 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 = "cpi"
    return temp_df