Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #3990

Merged
merged 3 commits into from
Jul 19, 2023
Merged

Dev #3990

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion akshare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2475,9 +2475,10 @@
1.10.58 fix: fix fund_etf_hist_em interface
1.10.59 add: add fund_announcement_personnel_em interface
1.10.60 add: add macro_usa_cpi_yoy interface
1.10.61 fix: fix macro_cnbs interface
"""

__version__ = "1.10.60"
__version__ = "1.10.61"
__author__ = "AKFamily"

import sys
Expand Down
24 changes: 22 additions & 2 deletions akshare/economic/marco_cnbs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
Date: 2023/3/22 20:22
Date: 2023/7/19 18:20
Desc: 国家金融与发展实验室-中国宏观杠杆率数据
http://114.115.232.154:8080/
"""
Expand All @@ -19,9 +19,26 @@ def macro_cnbs() -> pd.DataFrame:
temp_df = pd.read_excel(
url, sheet_name="Data", header=0, skiprows=1, engine="openpyxl"
)

temp_df["Period"] = pd.to_datetime(temp_df["Period"]).dt.strftime("%Y-%m")
temp_df.dropna(axis=1, inplace=True)
temp_df.columns = [

temp_df.rename(
columns={
"Period": "年份",
"Household": "居民部门",
"Non-financial corporations": "非金融企业部门",
"Central government ": "中央政府",
"Local government": "地方政府",
"General government": "政府部门",
"Non financial sector": "实体经济部门",
"Financial sector(asset side)": "金融部门资产方",
"Financial sector(liability side)": "金融部门负债方",
},
inplace=True,
)

column_order = [
"年份",
"居民部门",
"非金融企业部门",
Expand All @@ -32,6 +49,8 @@ def macro_cnbs() -> pd.DataFrame:
"金融部门资产方",
"金融部门负债方",
]
temp_df = temp_df.reindex(columns=column_order)

temp_df["居民部门"] = pd.to_numeric(temp_df["居民部门"], errors="coerce")
temp_df["非金融企业部门"] = pd.to_numeric(temp_df["非金融企业部门"], errors="coerce")
temp_df["政府部门"] = pd.to_numeric(temp_df["政府部门"], errors="coerce")
Expand All @@ -40,6 +59,7 @@ def macro_cnbs() -> pd.DataFrame:
temp_df["实体经济部门"] = pd.to_numeric(temp_df["实体经济部门"], errors="coerce")
temp_df["金融部门资产方"] = pd.to_numeric(temp_df["金融部门资产方"], errors="coerce")
temp_df["金融部门负债方"] = pd.to_numeric(temp_df["金融部门负债方"], errors="coerce")

return temp_df


Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@

## 更新说明详情

1.10.61 fix: fix macro_cnbs interface

1. 修复 macro_cnbs 接口

1.10.60 add: add macro_usa_cpi_yoy interface

1. 新增 macro_usa_cpi_yoy 接口
Expand Down Expand Up @@ -2654,6 +2658,8 @@

## 版本更新说明

1.10.61 fix: fix macro_cnbs interface

1.10.60 add: add macro_usa_cpi_yoy interface

1.10.59 add: add fund_announcement_personnel_em interface
Expand Down
25 changes: 13 additions & 12 deletions docs/data/macro/macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ print(macro_cnbs_df)
数据示例

```
年份 居民部门 非金融企业部门 ... 实体经济部门 金融部门资产方 金融部门负债方
0 1993-12 8.311222 91.658000 ... 107.791459 8.896441 7.128428
1 1994-12 7.808230 82.411703 ... 98.354271 9.808787 6.796868
2 1995-12 8.240004 80.950106 ... 97.850373 10.009081 7.006151
3 1996-03 8.403456 81.711651 ... 99.241521 10.183896 7.186300
4 1996-06 8.581114 82.051373 ... 99.679459 10.379730 7.380510
.. ... ... ... ... ... ... ...
93 2018-09 52.575456 155.641011 ... 245.227043 61.350917 60.645733
94 2018-12 53.198837 153.553140 ... 243.702122 60.638348 60.936158
95 2019-03 54.277928 156.881879 ... 248.828108 60.542178 59.417322
96 2019-06 55.304291 155.743313 ... 249.533412 58.736094 58.727086
97 2019-09 56.314848 155.618498 ... 251.147265 55.820243 59.358625
年份 居民部门 非金融企业部门 政府部门 中央政府 地方政府 实体经济部门 金融部门资产方 金融部门负债方
0 1992-12 7.5 90.0 8.3 4.4 3.9 105.8 7.8 7.2
1 1993-03 7.5 91.1 8.1 4.2 3.9 106.7 7.8 7.3
2 1993-06 7.4 91.1 8.2 4.4 3.8 106.7 7.7 7.3
3 1993-09 7.3 90.2 8.3 4.6 3.7 105.8 7.7 7.3
4 1993-12 7.0 87.8 7.8 4.2 3.6 102.6 8.9 7.1
.. ... ... ... ... ... ... ... ... ...
117 2022-03 61.8 158.2 47.3 19.9 27.4 267.3 49.2 62.6
118 2022-06 62.0 160.3 49.6 20.2 29.4 271.9 50.0 63.9
119 2022-09 62.1 160.9 49.8 20.9 28.9 272.7 49.3 63.9
120 2022-12 61.9 160.9 50.4 21.4 29.0 273.1 50.0 64.4
121 2023-03 63.3 167.0 51.5 21.4 30.1 281.8 52.7 65.6
[122 rows x 9 columns]
```

#### 国民经济运行状况
Expand Down
Loading