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

fix printing alignment issue on Chinese env #20685

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

#### 建议安装方法
pip install gopup
##### 开发模式
```bash
git clone https://github.com/justinzm/gopup.git
cd gopup
pip install -e .
```

#### 升级方法
pip install gopup --upgrade
Expand Down
3 changes: 2 additions & 1 deletion gopup/economic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
# @Author : justin.郑 3907721@qq.com
# @File : __init__.py.py
# @Desc : 宏观经济


import pandas as pd
pd.set_option("display.unicode.east_asian_width", True)
12 changes: 6 additions & 6 deletions gopup/economic/marco_cn.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_gdp_quarter():
--------
DataFrame
month :统计月份
cpi : "季度", "国内生产总值 绝对值(亿元)", "国内生产总值 同比增长", "第一产业 绝对值(亿元)", "第一产业 同比增长", "第二产业 绝对值(亿元)", "第二产业 同比增长", "第三产业 绝对值(亿元)", "第三产业 同比增长"
cpi : "季度", "国内生产总值(亿元)", "同比增长", "第一产业(亿元)", "同比增长", "第二产业(亿元)", "同比增长", "第三产业(亿元)", "同比增长"
"""
url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx"
params = {
Expand All @@ -58,7 +58,7 @@ def get_gdp_quarter():
res_list = []
for li in tmp_list:
res_list.append(li.split(','))
columns = ["季度", "国内生产总值 绝对值(亿元)", "国内生产总值 同比增长", "第一产业 绝对值(亿元)", "第一产业 同比增长", "第二产业 绝对值(亿元)", "第二产业 同比增长", "第三产业 绝对值(亿元)", "第三产业 同比增长"]
columns = ["季度", "国内生产总值(亿元)", "同比增长", "第一产业(亿元)", "同比增长", "第二产业(亿元)", "同比增长", "第三产业(亿元)", "同比增长"]
data_df = pd.DataFrame(res_list, columns=columns)
return data_df

Expand Down Expand Up @@ -123,7 +123,7 @@ def get_pmi():
获取采购经理人指数(PMI)
--------
DataFrame
"月份", "制造业指数", "制造业同比增长", "非制造业指数", "非制造业同比增长"
"月份", "制造业指数", "同比增长", "非制造业指数", "同比增长"
"""
url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx"
params = {
Expand All @@ -140,7 +140,7 @@ def get_pmi():
res_list = []
for li in tmp_list:
res_list.append(li.split(','))
columns = ["月份", "制造业指数", "制造业同比增长", "非制造业指数", "非制造业同比增长"]
columns = ["月份", "制造业指数", "同比增长", "非制造业指数", "同比增长"]
data_df = pd.DataFrame(res_list, columns=columns)
return data_df

Expand Down Expand Up @@ -177,7 +177,7 @@ def get_money_supply():
获取货币供应量数据
--------
DataFrame
"月份", "货币和准货币(M2) 数量(亿元)", "货币和准货币(M2) 同比增长", "货币和准货币(M2) 环比增长", "货币(M1) 数量(亿元)", "货币(M1) 同比增长 ", "货币(M1) 环比增长", "流通中的现金(M0) 数量(亿元)", "流通中的现金(M0) 同比增长", "流通中的现金(M0) 环比增长"
"月份", "货币M2(亿元)", "同比增长", "环比增长", "货币M1 数量(亿元)", "同比增长 ", "环比增长", "流通中的现金(M0) 数量(亿元)", "同比增长", "环比增长"
"""
url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx"
params = {
Expand Down Expand Up @@ -205,7 +205,7 @@ def get_gold_and_foreign_reserves():
Returns
-------
DataFrame
"月份", "国家外汇储备(亿美元) 数值", "国家外汇储备(亿美元) 同比", "国家外汇储备(亿美元) 环比", "黄金储备(万盎司) 数值", "黄金储备(万盎司) 同比", "黄金储备(万盎司) 环比"
"月份", "国家外汇储备(亿美元) 数值", "同比", "环比", "黄金储备(万盎司) 数值", "同比", "环比"
"""
url = "http://datainterface.eastmoney.com/EM_DataCenter/JS.aspx"
params = {
Expand Down
34 changes: 6 additions & 28 deletions gopup/economic/shibor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
from gopup.utils import date_utils as du


def shibor_data(year=None):
def shibor_data():
"""
获取上海银行间同业拆放利率(Shibor)
Parameters
------
year:年份(int)

Return
------
Expand All @@ -32,16 +29,10 @@ def shibor_data(year=None):
6M:6个月拆放利率
9M:9个月拆放利率
1Y:1年拆放利率

http://www.shibor.org/shibor/web/html/downLoad.html?nameNew=Historical_Shibor_Data_2019.xls&downLoadPath=data&nameOld=Shibor数据2019.xls&shiborSrc=http://www.shibor.org/shibor/
https://www.shibor.org/dqs/rest/cm-u-bk-shibor/ShiborHisExcel?lang=cn
"""
year = du.get_year() if year is None else year
lab = cons.SHIBOR_TYPE['Shibor']
try:
url = cons.SHIBOR_DATA_URL % (cons.P_TYPE['http'], cons.DOMAINS['shibor'],
cons.PAGES['dw'], 'Shibor',
year, lab,
year)
url = 'https://www.shibor.org/dqs/rest/cm-u-bk-shibor/ShiborHisExcel?lang=cn'
herder = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
Expand All @@ -51,8 +42,6 @@ def shibor_data(year=None):

r = requests.get(url, headers=herder)
df = pd.read_excel(r.content)
df.columns = cons.SHIBOR_COLS
df['date'] = df['date'].map(lambda x: x.date())
return df
except Exception as e:
return None
Expand Down Expand Up @@ -110,25 +99,16 @@ def shibor_quote_data(year=None):
return None


def shibor_ma_data(year=None):
def shibor_ma_data():
"""
获取Shibor均值数据
Parameters
------
year:年份(int)

Return
------
date:日期
其它分别为各周期5、10、20均价
"""
year = du.get_year() if year is None else year
lab = cons.SHIBOR_TYPE['Tendency']
try:
url = cons.SHIBOR_DATA_URL % (cons.P_TYPE['http'], cons.DOMAINS['shibor'],
cons.PAGES['dw'], 'Shibor_Tendency',
year, lab,
year)
url = 'https://www.shibor.org/dqs/rest/cm-u-bk-shibor/ShiborMnHisExcel?lang=cn'
herder = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
Expand All @@ -138,8 +118,6 @@ def shibor_ma_data(year=None):

r = requests.get(url, headers=herder)
df = pd.read_excel(r.content)
df.columns = cons.SHIBOR_MA_COLS
df['date'] = df['date'].map(lambda x: x.date())
return df
except:
return None
Expand Down Expand Up @@ -185,7 +163,7 @@ def lpr_data(startDate, endDate):


if __name__ == "__main__":
tmp = shibor_data(2019)
tmp = shibor_data()
print(tmp)