Skip to content

Commit

Permalink
feat(macro_china_mobile_number): add macro_china_mobile_number interface
Browse files Browse the repository at this point in the history
add macro_china_mobile_number interface
  • Loading branch information
ak-quant committed Mar 29, 2022
1 parent 5e68d7b commit 9ce8b2b
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
4 changes: 3 additions & 1 deletion akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1914,9 +1914,10 @@
1.4.91 fix: fix macro_china_new_financial_credit interface
1.4.92 add: add stock_lhb_hyyyb_em interface
1.4.93 add: add macro_china_insurance_income interface
1.4.94 add: add macro_china_mobile_number interface
"""

__version__ = "1.4.93"
__version__ = "1.4.94"
__author__ = "AKFamily"

import sys
Expand Down Expand Up @@ -3653,6 +3654,7 @@
from akshare.economic.macro_china import (
macro_china_bank_financing,
macro_china_insurance_income,
macro_china_mobile_number,
macro_china_cpi_monthly,
macro_china_cpi_yearly,
macro_china_m2_yearly,
Expand Down
46 changes: 46 additions & 0 deletions akshare/economic/macro_china.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,52 @@ def macro_china_insurance_income() -> pd.DataFrame:
return temp_df


def macro_china_mobile_number() -> pd.DataFrame:
"""
手机出货量
https://data.eastmoney.com/cjsj/hyzs_list_EMI00225823.html
:return: 手机出货量
:rtype: pandas.DataFrame
"""
url = "https://datacenter-web.eastmoney.com/api/data/v1/get"
params = {
'sortColumns': 'REPORT_DATE',
'sortTypes': '-1',
'pageSize': '1000',
'pageNumber': '1',
'reportName': 'RPT_INDUSTRY_INDEX',
'columns': 'REPORT_DATE,INDICATOR_VALUE,CHANGE_RATE,CHANGERATE_3M,CHANGERATE_6M,CHANGERATE_1Y,CHANGERATE_2Y,CHANGERATE_3Y',
'filter': '(INDICATOR_ID="EMI00225823")',
'source': 'WEB',
'client': 'WEB',
}
r = requests.get(url, params=params)
data_json = r.json()
temp_df = pd.DataFrame(data_json['result']["data"])
temp_df.drop_duplicates(inplace=True)
temp_df.columns = [
"日期",
"最新值",
"涨跌幅",
'近3月涨跌幅',
'近6月涨跌幅',
'近1年涨跌幅',
'近2年涨跌幅',
'近3年涨跌幅',
]
temp_df["日期"] = pd.to_datetime(temp_df["日期"]).dt.date
temp_df["最新值"] = pd.to_numeric(temp_df["最新值"])
temp_df["涨跌幅"] = pd.to_numeric(temp_df["涨跌幅"])
temp_df["近3月涨跌幅"] = pd.to_numeric(temp_df["近3月涨跌幅"])
temp_df["近6月涨跌幅"] = pd.to_numeric(temp_df["近6月涨跌幅"])
temp_df["近1年涨跌幅"] = pd.to_numeric(temp_df["近1年涨跌幅"])
temp_df["近2年涨跌幅"] = pd.to_numeric(temp_df["近2年涨跌幅"])
temp_df["近3年涨跌幅"] = pd.to_numeric(temp_df["近3年涨跌幅"])
temp_df.sort_values(['日期'], inplace=True)
temp_df.reset_index(inplace=True, drop=True)
return temp_df


def macro_china_new_financial_credit() -> pd.DataFrame:
"""
中国-新增信贷数据
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

## 更新说明

1.4.94 add: add macro_china_mobile_number interface

1. 新增 macro_china_mobile_number 接口,获取手机出货量数据

1.4.93 add: add macro_china_insurance_income interface

1. 新增 macro_china_insurance_income 接口,获取原保险保费收入数据
Expand Down Expand Up @@ -229,6 +233,8 @@

## 版本更新说明

1.4.94 add: add macro_china_mobile_number interface

1.4.93 add: add macro_china_insurance_income interface

1.4.92 add: add stock_lhb_hyyyb_em interface
Expand Down
55 changes: 55 additions & 0 deletions docs/data/macro/macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,61 @@ print(macro_china_insurance_income_df)
209 2022-01-01 7.049640e+07 -70.092958 ... -5.768089 5.429366 12.398597
```

##### 手机出货量

接口: macro_china_mobile_number

目标地址: https://data.eastmoney.com/cjsj/hyzs_list_EMI00225823.html

描述: 手机出货量, 数据区间从 201201-至今

限量: 单次返回所有历史数据

输入参数

| 名称 | 类型 | 描述 |
|-----|-----|-----|
| - | - | - |

输出参数

| 名称 | 类型 | 描述 |
|--------|---------|---------|
| 日期 | object | - |
| 最新值 | int64 | - |
| 涨跌幅 | float64 | 注意单位: % |
| 近3月涨跌幅 | float64 | 注意单位: % |
| 近6月涨跌幅 | float64 | 注意单位: % |
| 近1年涨跌幅 | float64 | 注意单位: % |
| 近2年涨跌幅 | float64 | 注意单位: % |
| 近3年涨跌幅 | float64 | 注意单位: % |

接口示例

```python
import akshare as ak

macro_china_mobile_number_df = ak.macro_china_mobile_number()
print(macro_china_mobile_number_df)
```

数据示例

```
日期 最新值 涨跌幅 ... 近1年涨跌幅 近2年涨跌幅 近3年涨跌幅
0 2012-01-01 2400.6 NaN ... NaN NaN NaN
1 2012-02-01 2998.9 24.922936 ... NaN NaN NaN
2 2012-03-01 3958.6 32.001734 ... NaN NaN NaN
3 2012-04-01 3528.7 -10.859900 ... NaN NaN NaN
4 2012-05-01 3586.8 1.646499 ... NaN NaN NaN
.. ... ... ... ... ... ... ...
117 2021-10-01 3357.5 56.599813 ... 28.379153 -6.655731 -12.866893
118 2021-11-01 3525.2 4.994788 ... 19.159005 1.176741 -0.333616
119 2021-12-01 3340.1 -5.250766 ... 25.591277 9.712916 -6.371587
120 2022-01-01 3302.2 -1.134697 ... -17.691924 58.660453 -3.013393
121 2022-02-01 1486.4 -54.987584 ... -31.688037 132.832080 2.432637
```

##### 新增信贷数据

接口: macro_china_new_financial_credit
Expand Down
3 changes: 3 additions & 0 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,9 @@
# 投资组合-重大变动
"fund_portfolio_change_em" # 天天基金网-基金档案-投资组合-重大变动
"fund_portfolio_industry_allocation_em" # 天天基金网-基金档案-投资组合-行业配置
# 中国宏观
"macro_china_insurance_income" # 原保险保费收入
"macro_china_mobile_number" # 手机出货量
```

## 案例演示
Expand Down

0 comments on commit 9ce8b2b

Please sign in to comment.