akshare 1.12.99__py3-none-any.whl → 1.15.72__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of akshare might be problematic. Click here for more details.
- akshare/__init__.py +441 -138
- akshare/air/air_hebei.py +79 -53
- akshare/air/air_zhenqi.py +29 -43
- akshare/air/sunrise_tad.py +32 -17
- akshare/bank/bank_cbirc_2020.py +12 -9
- akshare/bond/bond_cb_ths.py +17 -9
- akshare/bond/bond_china.py +38 -39
- akshare/bond/bond_china_money.py +75 -48
- akshare/bond/bond_info_cm.py +28 -8
- akshare/bond/bond_issue_cninfo.py +73 -30
- akshare/bond/bond_zh_cov.py +1 -1
- akshare/bond/bond_zh_sina.py +57 -51
- akshare/cal/__init__.py +0 -0
- akshare/cal/rv.py +170 -0
- akshare/cost/cost_living.py +7 -5
- akshare/currency/currency_safe.py +7 -6
- akshare/data/cninfo.js +15 -0
- akshare/datasets.py +10 -21
- akshare/economic/macro_bank.py +95 -653
- akshare/economic/macro_china.py +772 -1024
- akshare/economic/macro_china_hk.py +65 -243
- akshare/economic/macro_china_nbs.py +24 -7
- akshare/economic/macro_constitute.py +17 -12
- akshare/economic/macro_euro.py +13 -6
- akshare/economic/macro_finance_ths.py +133 -0
- akshare/economic/macro_info_ws.py +100 -0
- akshare/economic/macro_japan.py +5 -4
- akshare/economic/macro_other.py +12 -9
- akshare/economic/macro_usa.py +376 -1940
- akshare/economic/marco_cnbs.py +11 -6
- akshare/energy/energy_carbon.py +94 -125
- akshare/event/migration.py +3 -2
- akshare/exceptions.py +43 -0
- akshare/file_fold/calendar.json +245 -2
- akshare/fortune/fortune_500.py +15 -48
- akshare/fund/fund_amac.py +157 -75
- akshare/fund/fund_em.py +191 -184
- akshare/fund/fund_etf_em.py +16 -15
- akshare/fund/fund_etf_sina.py +71 -23
- akshare/fund/fund_etf_ths.py +93 -0
- akshare/fund/fund_fee_em.py +98 -0
- akshare/fund/fund_portfolio_em.py +60 -50
- akshare/fund/fund_rank_em.py +91 -82
- akshare/fund/fund_report_cninfo.py +63 -48
- akshare/fund/fund_scale_sina.py +20 -10
- akshare/fund/fund_xq.py +139 -109
- akshare/futures/cons.py +8 -31
- akshare/futures/cot.py +185 -137
- akshare/futures/futures_basis.py +97 -32
- akshare/futures/futures_comm_ctp.py +37 -0
- akshare/futures/futures_comm_qihuo.py +74 -45
- akshare/futures/futures_daily_bar.py +121 -184
- akshare/futures/futures_hf_em.py +66 -61
- akshare/futures/futures_hq_sina.py +79 -61
- akshare/futures/futures_index_ccidx.py +6 -3
- akshare/futures/futures_inventory_99.py +61 -272
- akshare/futures/futures_news_shmet.py +4 -2
- akshare/futures/futures_roll_yield.py +12 -25
- akshare/futures/futures_spot_stock_em.py +19 -13
- akshare/futures/futures_stock_js.py +14 -12
- akshare/futures/futures_to_spot.py +38 -33
- akshare/futures/futures_warehouse_receipt.py +75 -71
- akshare/futures/futures_zh_sina.py +5 -5
- akshare/futures/symbol_var.py +18 -13
- akshare/futures_derivative/futures_contract_info_czce.py +60 -52
- akshare/futures_derivative/futures_contract_info_ine.py +43 -34
- akshare/futures_derivative/futures_contract_info_shfe.py +46 -35
- akshare/futures_derivative/futures_cot_sina.py +26 -19
- akshare/futures_derivative/futures_spot_sys.py +21 -8
- akshare/fx/currency_investing.py +19 -285
- akshare/index/index_cflp.py +29 -26
- akshare/index/index_cni.py +86 -88
- akshare/index/index_cons.py +26 -10
- akshare/index/index_cx.py +248 -47
- akshare/index/index_drewry.py +17 -16
- akshare/index/index_option_qvix.py +329 -0
- akshare/index/index_research_fund_sw.py +134 -0
- akshare/index/{index_sw_research.py → index_research_sw.py} +122 -58
- akshare/index/index_spot.py +9 -5
- akshare/index/index_stock_hk.py +35 -16
- akshare/index/index_stock_us_sina.py +1 -1
- akshare/index/index_stock_zh.py +180 -89
- akshare/index/index_stock_zh_csindex.py +15 -369
- akshare/index/index_sw.py +62 -34
- akshare/index/index_yw.py +46 -23
- akshare/index/index_zh_a_scope.py +48 -0
- akshare/index/index_zh_em.py +6 -4
- akshare/interest_rate/interbank_rate_em.py +14 -9
- akshare/movie/artist_yien.py +32 -5
- akshare/movie/movie_yien.py +92 -18
- akshare/movie/video_yien.py +28 -5
- akshare/news/news_baidu.py +78 -44
- akshare/news/news_cctv.py +38 -38
- akshare/news/news_stock.py +6 -3
- akshare/nlp/nlp_interface.py +7 -8
- akshare/option/cons.py +11 -11
- akshare/option/option_comm_qihuo.py +86 -0
- akshare/option/option_commodity.py +178 -51
- akshare/option/option_daily_stats_sse_szse.py +146 -0
- akshare/option/option_em.py +147 -138
- akshare/option/option_finance_sina.py +160 -137
- akshare/option/option_lhb_em.py +62 -56
- akshare/option/option_risk_indicator_sse.py +17 -14
- akshare/other/other_car_cpca.py +934 -0
- akshare/other/{other_car.py → other_car_gasgoo.py} +15 -54
- akshare/qdii/__init__.py +0 -0
- akshare/qdii/qdii_jsl.py +233 -0
- akshare/request.py +117 -0
- akshare/spot/spot_hog_soozhu.py +232 -0
- akshare/spot/spot_price_qh.py +121 -0
- akshare/spot/spot_sge.py +63 -10
- akshare/stock/stock_allotment_cninfo.py +10 -9
- akshare/stock/stock_board_concept_em.py +23 -14
- akshare/stock/stock_board_industry_em.py +40 -34
- akshare/stock/stock_cg_equity_mortgage.py +15 -11
- akshare/stock/stock_cg_guarantee.py +41 -51
- akshare/stock/stock_cg_lawsuit.py +36 -35
- akshare/stock/stock_dividend_cninfo.py +12 -6
- akshare/stock/stock_dzjy_em.py +347 -260
- akshare/stock/stock_fund_em.py +332 -84
- akshare/stock/stock_hk_famous.py +108 -0
- akshare/stock/stock_hk_sina.py +8 -7
- akshare/stock/stock_hold_control_cninfo.py +100 -15
- akshare/stock/stock_hold_control_em.py +4 -3
- akshare/stock/stock_hold_num_cninfo.py +18 -12
- akshare/stock/stock_hot_rank_em.py +2 -1
- akshare/stock/stock_hot_search_baidu.py +5 -2
- akshare/stock/stock_industry_cninfo.py +24 -18
- akshare/stock/stock_industry_pe_cninfo.py +45 -31
- akshare/stock/stock_industry_sw.py +9 -10
- akshare/stock/stock_info.py +25 -15
- akshare/stock/stock_info_em.py +5 -2
- akshare/stock/stock_intraday_em.py +5 -2
- akshare/stock/stock_intraday_sina.py +22 -18
- akshare/stock/stock_ipo_summary_cninfo.py +25 -10
- akshare/stock/stock_new_cninfo.py +32 -19
- akshare/stock/stock_news_cx.py +39 -0
- akshare/stock/stock_profile_cninfo.py +9 -8
- akshare/stock/stock_rank_forecast.py +8 -6
- akshare/stock/stock_share_changes_cninfo.py +18 -14
- akshare/stock/stock_share_hold.py +24 -19
- akshare/stock/stock_summary.py +54 -26
- akshare/stock/stock_us_famous.py +15 -6
- akshare/stock/stock_us_pink.py +7 -5
- akshare/stock/stock_us_sina.py +15 -12
- akshare/stock/stock_xq.py +38 -12
- akshare/stock/stock_zh_a_sina.py +53 -78
- akshare/stock/stock_zh_b_sina.py +32 -55
- akshare/stock/stock_zh_kcb_report.py +11 -9
- akshare/stock/stock_zh_kcb_sina.py +67 -64
- akshare/stock_feature/stock_a_below_net_asset_statistics.py +5 -2
- akshare/stock_feature/stock_a_high_low.py +5 -2
- akshare/stock_feature/stock_a_indicator.py +12 -9
- akshare/stock_feature/stock_a_pe_and_pb.py +27 -6
- akshare/stock_feature/stock_account_em.py +58 -40
- akshare/stock_feature/stock_analyst_em.py +36 -27
- akshare/stock_feature/stock_board_industry_ths.py +136 -400
- akshare/stock_feature/stock_comment_em.py +118 -85
- akshare/stock_feature/stock_concept_futu.py +183 -0
- akshare/stock_feature/stock_cyq_em.py +58 -54
- akshare/stock_feature/stock_disclosure_cninfo.py +147 -102
- akshare/stock_feature/stock_esg_sina.py +216 -11
- akshare/stock_feature/stock_fhps_em.py +60 -25
- akshare/stock_feature/stock_fhps_ths.py +25 -6
- akshare/stock_feature/stock_fund_flow.py +38 -25
- akshare/stock_feature/stock_gdfx_em.py +180 -95
- akshare/stock_feature/stock_gdhs.py +73 -49
- akshare/stock_feature/stock_gpzy_em.py +78 -46
- akshare/stock_feature/stock_hist_em.py +55 -23
- akshare/stock_feature/stock_hk_valuation_baidu.py +20 -8
- akshare/stock_feature/stock_hsgt_em.py +184 -452
- akshare/stock_feature/stock_info.py +52 -29
- akshare/stock_feature/stock_inner_trade_xq.py +39 -31
- akshare/stock_feature/stock_irm_cninfo.py +32 -9
- akshare/stock_feature/stock_jgdy_em.py +41 -38
- akshare/stock_feature/stock_lh_yybpm.py +36 -37
- akshare/stock_feature/stock_lhb_em.py +135 -71
- akshare/stock_feature/stock_lhb_sina.py +93 -46
- akshare/stock_feature/stock_margin_em.py +102 -0
- akshare/stock_feature/{stock_sse_margin.py → stock_margin_sse.py} +21 -15
- akshare/stock_feature/{stock_szse_margin.py → stock_margin_szse.py} +23 -19
- akshare/stock_feature/stock_market_legu.py +13 -8
- akshare/stock_feature/stock_pankou_em.py +72 -34
- akshare/stock_feature/stock_report_em.py +244 -54
- akshare/stock_feature/stock_research_report_em.py +48 -19
- akshare/stock_feature/stock_sns_sseinfo.py +15 -12
- akshare/stock_feature/stock_sy_em.py +86 -33
- akshare/stock_feature/stock_technology_ths.py +152 -120
- akshare/stock_feature/stock_tfp_em.py +35 -13
- akshare/stock_feature/stock_three_report_em.py +119 -77
- akshare/stock_feature/stock_ttm_lyr.py +4 -7
- akshare/stock_feature/stock_value_em.py +83 -0
- akshare/stock_feature/stock_wencai.py +21 -9
- akshare/stock_feature/stock_yjyg_em.py +63 -28
- akshare/stock_feature/stock_zf_pg.py +61 -38
- akshare/stock_feature/stock_zh_valuation_baidu.py +3 -2
- akshare/stock_feature/stock_ztb_em.py +62 -40
- akshare/stock_fundamental/stock_finance.py +150 -58
- akshare/stock_fundamental/stock_finance_ths.py +116 -31
- akshare/stock_fundamental/stock_mda_ym.py +5 -3
- akshare/stock_fundamental/stock_notice.py +29 -15
- akshare/stock_fundamental/stock_profit_forecast_em.py +31 -13
- akshare/stock_fundamental/stock_profit_forecast_ths.py +19 -10
- akshare/stock_fundamental/stock_register_em.py +448 -0
- akshare/stock_fundamental/stock_restricted_em.py +79 -32
- akshare/stock_fundamental/stock_zygc.py +10 -8
- akshare/stock_fundamental/stock_zyjs_ths.py +5 -3
- akshare/tool/trade_date_hist.py +4 -3
- akshare/utils/cons.py +10 -0
- akshare/utils/context.py +43 -0
- akshare/utils/demjson.py +2 -2
- akshare/utils/func.py +26 -0
- akshare/utils/tqdm.py +13 -3
- {akshare-1.12.99.dist-info → akshare-1.15.72.dist-info}/METADATA +52 -69
- akshare-1.15.72.dist-info/RECORD +385 -0
- {akshare-1.12.99.dist-info → akshare-1.15.72.dist-info}/WHEEL +1 -1
- tests/test_func.py +3 -5
- akshare/bond/bond_futures.py +0 -50
- akshare/bond/bond_investing.py +0 -139
- akshare/crypto/crypto_hist_investing.py +0 -249
- akshare/fortune/fortune_it_juzi.py +0 -123
- akshare/futures/futures_international.py +0 -170
- akshare/futures/futures_news_baidu.py +0 -54
- akshare/futures/inventory_data.py +0 -100
- akshare/futures_derivative/futures_index_price_nh.py +0 -61
- akshare/futures_derivative/futures_index_return_nh.py +0 -47
- akshare/futures_derivative/futures_index_volatility_nh.py +0 -51
- akshare/futures_derivative/futures_other_index_nh.py +0 -145
- akshare/index/index_fear_greed_funddb.py +0 -71
- akshare/index/index_investing.py +0 -232
- akshare/sport/sport_olympic_winter.py +0 -39
- akshare/stock_feature/stock_board_concept_ths.py +0 -422
- akshare/stock_fundamental/stock_register.py +0 -292
- akshare-1.12.99.dist-info/RECORD +0 -374
- {akshare-1.12.99.dist-info → akshare-1.15.72.dist-info}/LICENSE +0 -0
- {akshare-1.12.99.dist-info → akshare-1.15.72.dist-info}/top_level.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# -*- coding:utf-8 -*-
|
|
3
3
|
"""
|
|
4
|
-
Date:
|
|
4
|
+
Date: 2024/10/2 9:00
|
|
5
5
|
Desc: 股票基本面数据
|
|
6
6
|
新浪财经-财务报表-财务摘要
|
|
7
7
|
https://vip.stock.finance.sina.com.cn/corp/go.php/vFD_FinanceSummary/stockid/600004.phtml
|
|
@@ -10,13 +10,15 @@ https://money.finance.sina.com.cn/corp/go.php/vFD_FinancialGuideLine/stockid/600
|
|
|
10
10
|
新浪财经-发行与分配
|
|
11
11
|
https://money.finance.sina.com.cn/corp/go.php/vISSUE_ShareBonus/stockid/600004.phtml
|
|
12
12
|
"""
|
|
13
|
+
|
|
13
14
|
from datetime import datetime
|
|
14
15
|
from io import StringIO
|
|
15
16
|
|
|
16
17
|
import pandas as pd
|
|
17
18
|
import requests
|
|
18
19
|
from bs4 import BeautifulSoup
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
from akshare.utils.tqdm import get_tqdm
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
def stock_financial_report_sina(
|
|
@@ -39,7 +41,7 @@ def stock_financial_report_sina(
|
|
|
39
41
|
"source": symbol_map[symbol],
|
|
40
42
|
"type": "0",
|
|
41
43
|
"page": "1",
|
|
42
|
-
"num": "
|
|
44
|
+
"num": "1000",
|
|
43
45
|
}
|
|
44
46
|
r = requests.get(url, params=params)
|
|
45
47
|
data_json = r.json()
|
|
@@ -55,7 +57,7 @@ def stock_financial_report_sina(
|
|
|
55
57
|
temp_df = temp_df[["item_title", "item_value"]]
|
|
56
58
|
temp_df["item_value"] = pd.to_numeric(temp_df["item_value"], errors="coerce")
|
|
57
59
|
temp_tail_df = pd.DataFrame.from_dict(
|
|
58
|
-
{
|
|
60
|
+
data={
|
|
59
61
|
"数据源": data_json["result"]["data"]["report_list"][date_str][
|
|
60
62
|
"data_source"
|
|
61
63
|
],
|
|
@@ -65,7 +67,9 @@ def stock_financial_report_sina(
|
|
|
65
67
|
"公告日期": data_json["result"]["data"]["report_list"][date_str][
|
|
66
68
|
"publish_date"
|
|
67
69
|
],
|
|
68
|
-
"币种": data_json["result"]["data"]["report_list"][date_str][
|
|
70
|
+
"币种": data_json["result"]["data"]["report_list"][date_str][
|
|
71
|
+
"rCurrency"
|
|
72
|
+
],
|
|
69
73
|
"类型": data_json["result"]["data"]["report_list"][date_str]["rType"],
|
|
70
74
|
"更新日期": datetime.fromtimestamp(
|
|
71
75
|
data_json["result"]["data"]["report_list"][date_str]["update_time"]
|
|
@@ -75,13 +79,13 @@ def stock_financial_report_sina(
|
|
|
75
79
|
)
|
|
76
80
|
temp_tail_df.reset_index(inplace=True)
|
|
77
81
|
temp_tail_df.columns = ["item_title", "item_value"]
|
|
78
|
-
temp_df = pd.concat([temp_df, temp_tail_df], ignore_index=True)
|
|
82
|
+
temp_df = pd.concat(objs=[temp_df, temp_tail_df], ignore_index=True)
|
|
79
83
|
temp_df.columns = ["项目", date_str]
|
|
80
|
-
big_df = pd.concat([big_df, temp_df[date_str]], axis=1, ignore_index=True)
|
|
84
|
+
big_df = pd.concat(objs=[big_df, temp_df[date_str]], axis=1, ignore_index=True)
|
|
81
85
|
|
|
82
86
|
big_df = big_df.T
|
|
83
87
|
big_df.columns = temp_df["项目"]
|
|
84
|
-
big_df = pd.concat([pd.DataFrame({"报告日": df_columns}), big_df], axis=1)
|
|
88
|
+
big_df = pd.concat(objs=[pd.DataFrame({"报告日": df_columns}), big_df], axis=1)
|
|
85
89
|
# 此处有 '国内票证结算' 和 '内部应收款'字段重复
|
|
86
90
|
big_df = big_df.loc[:, ~big_df.columns.duplicated(keep="first")]
|
|
87
91
|
return big_df
|
|
@@ -102,7 +106,7 @@ def stock_financial_abstract(symbol: str = "600004") -> pd.DataFrame:
|
|
|
102
106
|
"source": "gjzb",
|
|
103
107
|
"type": "0",
|
|
104
108
|
"page": "1",
|
|
105
|
-
"num": "
|
|
109
|
+
"num": "1000",
|
|
106
110
|
}
|
|
107
111
|
r = requests.get(url, params=params)
|
|
108
112
|
data_json = r.json()
|
|
@@ -113,7 +117,9 @@ def stock_financial_abstract(symbol: str = "600004") -> pd.DataFrame:
|
|
|
113
117
|
big_df = temp_df["item_title"]
|
|
114
118
|
for item in key_list:
|
|
115
119
|
temp_df = pd.DataFrame(data_json["result"]["data"]["report_list"][item]["data"])
|
|
116
|
-
big_df = pd.concat(
|
|
120
|
+
big_df = pd.concat(
|
|
121
|
+
objs=[big_df, temp_df["item_value"]], axis=1, ignore_index=True
|
|
122
|
+
)
|
|
117
123
|
big_df.index = big_df.iloc[:, 0]
|
|
118
124
|
big_df = big_df.iloc[:, 1:]
|
|
119
125
|
|
|
@@ -153,7 +159,7 @@ def stock_financial_abstract(symbol: str = "600004") -> pd.DataFrame:
|
|
|
153
159
|
big_seven_df.insert(0, "选项", "营运能力")
|
|
154
160
|
|
|
155
161
|
big_df = pd.concat(
|
|
156
|
-
[
|
|
162
|
+
objs=[
|
|
157
163
|
big_one_df,
|
|
158
164
|
big_two_df,
|
|
159
165
|
big_three_df,
|
|
@@ -185,22 +191,37 @@ def stock_financial_analysis_indicator(
|
|
|
185
191
|
:return: 新浪财经-财务分析-财务指标
|
|
186
192
|
:rtype: pandas.DataFrame
|
|
187
193
|
"""
|
|
188
|
-
url =
|
|
194
|
+
url = (
|
|
195
|
+
f"https://money.finance.sina.com.cn/corp/go.php/vFD_FinancialGuideLine/"
|
|
196
|
+
f"stockid/{symbol}/ctrl/2020/displaytype/4.phtml"
|
|
197
|
+
)
|
|
189
198
|
r = requests.get(url)
|
|
190
|
-
soup = BeautifulSoup(r.text, "lxml")
|
|
199
|
+
soup = BeautifulSoup(r.text, features="lxml")
|
|
191
200
|
year_context = soup.find(attrs={"id": "con02-1"}).find("table").find_all("a")
|
|
192
201
|
year_list = [item.text for item in year_context]
|
|
193
202
|
if start_year in year_list:
|
|
194
203
|
year_list = year_list[: year_list.index(start_year) + 1]
|
|
195
204
|
out_df = pd.DataFrame()
|
|
205
|
+
tqdm = get_tqdm()
|
|
196
206
|
for year_item in tqdm(year_list, leave=False):
|
|
197
|
-
url =
|
|
207
|
+
url = (
|
|
208
|
+
f"https://money.finance.sina.com.cn/corp/go.php/vFD_FinancialGuideLine/"
|
|
209
|
+
f"stockid/{symbol}/ctrl/{year_item}/displaytype/4.phtml"
|
|
210
|
+
)
|
|
198
211
|
r = requests.get(url)
|
|
199
212
|
temp_df = pd.read_html(StringIO(r.text))[12].iloc[:, :-1]
|
|
200
213
|
temp_df.columns = temp_df.iloc[0, :]
|
|
201
214
|
temp_df = temp_df.iloc[1:, :]
|
|
202
215
|
big_df = pd.DataFrame()
|
|
203
|
-
indicator_list = [
|
|
216
|
+
indicator_list = [
|
|
217
|
+
"每股指标",
|
|
218
|
+
"盈利能力",
|
|
219
|
+
"成长能力",
|
|
220
|
+
"营运能力",
|
|
221
|
+
"偿债及资本结构",
|
|
222
|
+
"现金流量",
|
|
223
|
+
"其他指标",
|
|
224
|
+
]
|
|
204
225
|
for i in range(len(indicator_list)):
|
|
205
226
|
if i == 6:
|
|
206
227
|
inner_df = temp_df[
|
|
@@ -210,39 +231,53 @@ def stock_financial_analysis_indicator(
|
|
|
210
231
|
].T
|
|
211
232
|
else:
|
|
212
233
|
inner_df = temp_df[
|
|
213
|
-
temp_df.loc[
|
|
214
|
-
|
|
234
|
+
temp_df.loc[
|
|
235
|
+
temp_df.iloc[:, 0].str.find(indicator_list[i]) == 0, :
|
|
236
|
+
].index[0] : temp_df.loc[
|
|
215
237
|
temp_df.iloc[:, 0].str.find(indicator_list[i + 1]) == 0, :
|
|
216
|
-
]
|
|
217
|
-
.index[0]
|
|
238
|
+
].index[0]
|
|
218
239
|
- 1
|
|
219
240
|
].T
|
|
220
241
|
inner_df = inner_df.reset_index(drop=True)
|
|
221
|
-
big_df = pd.concat([big_df, inner_df], axis=1)
|
|
242
|
+
big_df = pd.concat(objs=[big_df, inner_df], axis=1)
|
|
222
243
|
big_df.columns = big_df.iloc[0, :].tolist()
|
|
223
244
|
big_df = big_df.iloc[1:, :]
|
|
224
245
|
big_df.index = temp_df.columns.tolist()[1:]
|
|
225
|
-
out_df = pd.concat([out_df, big_df])
|
|
246
|
+
out_df = pd.concat(objs=[out_df, big_df])
|
|
226
247
|
|
|
227
248
|
out_df.dropna(inplace=True)
|
|
228
249
|
out_df.reset_index(inplace=True)
|
|
229
250
|
out_df.rename(columns={"index": "日期"}, inplace=True)
|
|
251
|
+
out_df.sort_values(by=["日期"], ignore_index=True, inplace=True)
|
|
252
|
+
out_df["日期"] = pd.to_datetime(out_df["日期"], errors="coerce").dt.date
|
|
253
|
+
for item in out_df.columns[1:]:
|
|
254
|
+
out_df[item] = pd.to_numeric(out_df[item], errors="coerce")
|
|
230
255
|
return out_df
|
|
231
256
|
|
|
232
257
|
|
|
233
258
|
def stock_history_dividend() -> pd.DataFrame:
|
|
234
259
|
"""
|
|
235
260
|
新浪财经-发行与分配-历史分红
|
|
236
|
-
|
|
261
|
+
https://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/lsfh/index.phtml
|
|
237
262
|
:return: 所有股票的历史分红数据
|
|
238
263
|
:rtype: pandas.DataFrame
|
|
239
264
|
"""
|
|
240
|
-
url = "
|
|
241
|
-
params = {"p": "1", "num": "
|
|
265
|
+
url = "https://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/lsfh/index.phtml"
|
|
266
|
+
params = {"p": "1", "num": "50000"}
|
|
242
267
|
r = requests.get(url, params=params)
|
|
243
268
|
temp_df = pd.read_html(StringIO(r.text))[0]
|
|
244
269
|
temp_df["代码"] = temp_df["代码"].astype(str).str.zfill(6)
|
|
245
|
-
temp_df.columns = [
|
|
270
|
+
temp_df.columns = [
|
|
271
|
+
"代码",
|
|
272
|
+
"名称",
|
|
273
|
+
"上市日期",
|
|
274
|
+
"累计股息",
|
|
275
|
+
"年均股息",
|
|
276
|
+
"分红次数",
|
|
277
|
+
"融资总额",
|
|
278
|
+
"融资次数",
|
|
279
|
+
"详细",
|
|
280
|
+
]
|
|
246
281
|
temp_df["上市日期"] = pd.to_datetime(temp_df["上市日期"], errors="coerce").dt.date
|
|
247
282
|
temp_df["累计股息"] = pd.to_numeric(temp_df["累计股息"], errors="coerce")
|
|
248
283
|
temp_df["年均股息"] = pd.to_numeric(temp_df["年均股息"], errors="coerce")
|
|
@@ -269,7 +304,7 @@ def stock_history_dividend_detail(
|
|
|
269
304
|
:rtype: pandas.DataFrame
|
|
270
305
|
"""
|
|
271
306
|
if indicator == "分红":
|
|
272
|
-
url = f"
|
|
307
|
+
url = f"https://vip.stock.finance.sina.com.cn/corp/go.php/vISSUE_ShareBonus/stockid/{symbol}.phtml"
|
|
273
308
|
r = requests.get(url)
|
|
274
309
|
temp_df = pd.read_html(StringIO(r.text))[12]
|
|
275
310
|
temp_df.columns = [item[2] for item in temp_df.columns.tolist()]
|
|
@@ -287,7 +322,9 @@ def stock_history_dividend_detail(
|
|
|
287
322
|
del temp_df["查看详细"]
|
|
288
323
|
if temp_df.iloc[0, 0] == "暂时没有数据!":
|
|
289
324
|
return pd.DataFrame()
|
|
290
|
-
temp_df["公告日期"] = pd.to_datetime(
|
|
325
|
+
temp_df["公告日期"] = pd.to_datetime(
|
|
326
|
+
temp_df["公告日期"], errors="coerce"
|
|
327
|
+
).dt.date
|
|
291
328
|
temp_df["送股"] = pd.to_numeric(temp_df["送股"], errors="coerce")
|
|
292
329
|
temp_df["转增"] = pd.to_numeric(temp_df["转增"], errors="coerce")
|
|
293
330
|
temp_df["派息"] = pd.to_numeric(temp_df["派息"], errors="coerce")
|
|
@@ -314,7 +351,7 @@ def stock_history_dividend_detail(
|
|
|
314
351
|
else:
|
|
315
352
|
return temp_df
|
|
316
353
|
else:
|
|
317
|
-
url = f"
|
|
354
|
+
url = f"https://vip.stock.finance.sina.com.cn/corp/go.php/vISSUE_ShareBonus/stockid/{symbol}.phtml"
|
|
318
355
|
r = requests.get(url)
|
|
319
356
|
temp_df = pd.read_html(StringIO(r.text))[13]
|
|
320
357
|
temp_df.columns = [item[1] for item in temp_df.columns.tolist()]
|
|
@@ -334,11 +371,15 @@ def stock_history_dividend_detail(
|
|
|
334
371
|
del temp_df["查看详细"]
|
|
335
372
|
if temp_df.iloc[0, 0] == "暂时没有数据!":
|
|
336
373
|
return pd.DataFrame()
|
|
337
|
-
temp_df["公告日期"] = pd.to_datetime(
|
|
374
|
+
temp_df["公告日期"] = pd.to_datetime(
|
|
375
|
+
temp_df["公告日期"], errors="coerce"
|
|
376
|
+
).dt.date
|
|
338
377
|
temp_df["配股方案"] = pd.to_numeric(temp_df["配股方案"], errors="coerce")
|
|
339
378
|
temp_df["配股价格"] = pd.to_numeric(temp_df["配股价格"], errors="coerce")
|
|
340
379
|
temp_df["基准股本"] = pd.to_numeric(temp_df["基准股本"], errors="coerce")
|
|
341
|
-
temp_df["募集资金合计"] = pd.to_numeric(
|
|
380
|
+
temp_df["募集资金合计"] = pd.to_numeric(
|
|
381
|
+
temp_df["募集资金合计"], errors="coerce"
|
|
382
|
+
)
|
|
342
383
|
temp_df["除权日"] = pd.to_datetime(
|
|
343
384
|
temp_df["除权日"], format="%Y-%m-%d", errors="coerce"
|
|
344
385
|
).dt.date
|
|
@@ -406,8 +447,15 @@ def stock_add_stock(symbol: str = "688166") -> pd.DataFrame:
|
|
|
406
447
|
big_df[temp_df.name.split(" ")[1].split(":")[1][:10]] = temp_df
|
|
407
448
|
big_df = big_df.T
|
|
408
449
|
big_df.reset_index(inplace=True)
|
|
409
|
-
big_df.columns = [
|
|
410
|
-
|
|
450
|
+
big_df.columns = [
|
|
451
|
+
"公告日期",
|
|
452
|
+
"发行方式",
|
|
453
|
+
"发行价格",
|
|
454
|
+
"实际公司募集资金总额",
|
|
455
|
+
"发行费用总额",
|
|
456
|
+
"实际发行数量",
|
|
457
|
+
]
|
|
458
|
+
big_df["公告日期"] = pd.to_datetime(big_df["公告日期"], errors="coerce").dt.date
|
|
411
459
|
return big_df
|
|
412
460
|
|
|
413
461
|
|
|
@@ -423,11 +471,21 @@ def stock_restricted_release_queue_sina(symbol: str = "600000") -> pd.DataFrame:
|
|
|
423
471
|
url = f"https://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/xsjj/index.phtml?symbol={symbol}"
|
|
424
472
|
r = requests.get(url)
|
|
425
473
|
temp_df = pd.read_html(StringIO(r.text))[0]
|
|
426
|
-
temp_df.columns = [
|
|
474
|
+
temp_df.columns = [
|
|
475
|
+
"代码",
|
|
476
|
+
"名称",
|
|
477
|
+
"解禁日期",
|
|
478
|
+
"解禁数量",
|
|
479
|
+
"解禁股流通市值",
|
|
480
|
+
"上市批次",
|
|
481
|
+
"公告日期",
|
|
482
|
+
]
|
|
427
483
|
temp_df["解禁日期"] = pd.to_datetime(temp_df["解禁日期"], errors="coerce").dt.date
|
|
428
484
|
temp_df["公告日期"] = pd.to_datetime(temp_df["公告日期"], errors="coerce").dt.date
|
|
429
485
|
temp_df["解禁数量"] = pd.to_numeric(temp_df["解禁数量"], errors="coerce")
|
|
430
|
-
temp_df["解禁股流通市值"] = pd.to_numeric(
|
|
486
|
+
temp_df["解禁股流通市值"] = pd.to_numeric(
|
|
487
|
+
temp_df["解禁股流通市值"], errors="coerce"
|
|
488
|
+
)
|
|
431
489
|
temp_df["上市批次"] = pd.to_numeric(temp_df["上市批次"], errors="coerce")
|
|
432
490
|
temp_df["上市批次"] = pd.to_numeric(temp_df["上市批次"], errors="coerce")
|
|
433
491
|
return temp_df
|
|
@@ -443,21 +501,24 @@ def stock_circulate_stock_holder(symbol: str = "600000") -> pd.DataFrame:
|
|
|
443
501
|
:return: 新浪财经-股东股本-流通股东
|
|
444
502
|
:rtype: pandas.DataFrame
|
|
445
503
|
"""
|
|
504
|
+
pd.set_option("future.no_silent_downcasting", True)
|
|
446
505
|
url = f"https://vip.stock.finance.sina.com.cn/corp/go.php/vCI_CirculateStockHolder/stockid/{symbol}.phtml"
|
|
447
506
|
r = requests.get(url)
|
|
448
507
|
temp_df = pd.read_html(StringIO(r.text))[13].iloc[:, :5]
|
|
449
508
|
temp_df.columns = [*range(5)]
|
|
450
509
|
big_df = pd.DataFrame()
|
|
451
|
-
need_range = temp_df[
|
|
452
|
-
|
|
453
|
-
]
|
|
510
|
+
need_range = temp_df[
|
|
511
|
+
temp_df.iloc[:, 0].str.find("截止日期") == 0
|
|
512
|
+
].index.tolist() + [len(temp_df)]
|
|
513
|
+
tqdm = get_tqdm()
|
|
454
514
|
for i in tqdm(range(len(need_range) - 1), leave=False):
|
|
455
515
|
truncated_df = temp_df.iloc[need_range[i] : need_range[i + 1], :]
|
|
456
516
|
truncated_df = truncated_df.dropna(how="all")
|
|
457
517
|
temp_truncated = truncated_df.iloc[2:, :]
|
|
458
518
|
temp_truncated.reset_index(inplace=True, drop=True)
|
|
459
519
|
concat_df = pd.concat(
|
|
460
|
-
[temp_truncated, truncated_df.iloc[0, :], truncated_df.iloc[1, :]],
|
|
520
|
+
objs=[temp_truncated, truncated_df.iloc[0, :], truncated_df.iloc[1, :]],
|
|
521
|
+
axis=1,
|
|
461
522
|
)
|
|
462
523
|
concat_df.columns = concat_df.iloc[0, :]
|
|
463
524
|
concat_df = concat_df.iloc[1:, :]
|
|
@@ -465,7 +526,7 @@ def stock_circulate_stock_holder(symbol: str = "600000") -> pd.DataFrame:
|
|
|
465
526
|
# try for pandas >= 2.1.0
|
|
466
527
|
concat_df["截止日期"] = concat_df["截止日期"].ffill()
|
|
467
528
|
concat_df["公告日期"] = concat_df["公告日期"].ffill()
|
|
468
|
-
except
|
|
529
|
+
except: # noqa: E722
|
|
469
530
|
try:
|
|
470
531
|
# try for pandas < 2.1.0
|
|
471
532
|
concat_df["截止日期"] = concat_df["截止日期"].fillna(method="ffill")
|
|
@@ -473,10 +534,28 @@ def stock_circulate_stock_holder(symbol: str = "600000") -> pd.DataFrame:
|
|
|
473
534
|
except Exception as e:
|
|
474
535
|
print("Error:", e)
|
|
475
536
|
|
|
476
|
-
big_df = pd.concat([big_df, concat_df], axis=0, ignore_index=True)
|
|
537
|
+
big_df = pd.concat(objs=[big_df, concat_df], axis=0, ignore_index=True)
|
|
477
538
|
|
|
478
|
-
big_df = big_df[
|
|
479
|
-
|
|
539
|
+
big_df = big_df[
|
|
540
|
+
[
|
|
541
|
+
"截止日期",
|
|
542
|
+
"公告日期",
|
|
543
|
+
"编号",
|
|
544
|
+
"股东名称",
|
|
545
|
+
"持股数量(股)",
|
|
546
|
+
"占流通股比例(%)",
|
|
547
|
+
"股本性质",
|
|
548
|
+
]
|
|
549
|
+
]
|
|
550
|
+
big_df.columns = [
|
|
551
|
+
"截止日期",
|
|
552
|
+
"公告日期",
|
|
553
|
+
"编号",
|
|
554
|
+
"股东名称",
|
|
555
|
+
"持股数量",
|
|
556
|
+
"占流通股比例",
|
|
557
|
+
"股本性质",
|
|
558
|
+
]
|
|
480
559
|
|
|
481
560
|
big_df["截止日期"] = pd.to_datetime(big_df["截止日期"], errors="coerce").dt.date
|
|
482
561
|
big_df["公告日期"] = pd.to_datetime(big_df["公告日期"], errors="coerce").dt.date
|
|
@@ -501,22 +580,23 @@ def stock_fund_stock_holder(symbol: str = "600004") -> pd.DataFrame:
|
|
|
501
580
|
temp_df = pd.read_html(StringIO(r.text))[13].iloc[:, :6]
|
|
502
581
|
temp_df.columns = [*range(6)]
|
|
503
582
|
big_df = pd.DataFrame()
|
|
504
|
-
need_range = temp_df[
|
|
505
|
-
|
|
506
|
-
]
|
|
583
|
+
need_range = temp_df[
|
|
584
|
+
temp_df.iloc[:, 0].str.find("截止日期") == 0
|
|
585
|
+
].index.tolist() + [len(temp_df)]
|
|
586
|
+
tqdm = get_tqdm()
|
|
507
587
|
for i in tqdm(range(len(need_range) - 1), leave=False):
|
|
508
588
|
# pass
|
|
509
589
|
truncated_df = temp_df.iloc[need_range[i] : need_range[i + 1], :]
|
|
510
590
|
truncated_df = truncated_df.dropna(how="all")
|
|
511
591
|
temp_truncated = truncated_df.iloc[2:, :]
|
|
512
592
|
temp_truncated.reset_index(inplace=True, drop=True)
|
|
513
|
-
concat_df = pd.concat([temp_truncated, truncated_df.iloc[0, 1:]], axis=1)
|
|
593
|
+
concat_df = pd.concat(objs=[temp_truncated, truncated_df.iloc[0, 1:]], axis=1)
|
|
514
594
|
concat_df.columns = truncated_df.iloc[1, :].tolist() + ["截止日期"]
|
|
515
595
|
try:
|
|
516
596
|
# try for pandas >= 2.1.0
|
|
517
597
|
concat_df["截止日期"] = concat_df["截止日期"].ffill()
|
|
518
598
|
concat_df["截止日期"] = concat_df["截止日期"].ffill()
|
|
519
|
-
except
|
|
599
|
+
except: # noqa: E722
|
|
520
600
|
try:
|
|
521
601
|
# try for pandas < 2.1.0
|
|
522
602
|
concat_df["截止日期"] = concat_df["截止日期"].fillna(method="ffill")
|
|
@@ -524,10 +604,18 @@ def stock_fund_stock_holder(symbol: str = "600004") -> pd.DataFrame:
|
|
|
524
604
|
except Exception as e:
|
|
525
605
|
print("Error:", e)
|
|
526
606
|
|
|
527
|
-
big_df = pd.concat([big_df, concat_df], axis=0, ignore_index=True)
|
|
607
|
+
big_df = pd.concat(objs=[big_df, concat_df], axis=0, ignore_index=True)
|
|
528
608
|
big_df.dropna(inplace=True)
|
|
529
609
|
big_df.reset_index(inplace=True, drop=True)
|
|
530
|
-
big_df.columns = [
|
|
610
|
+
big_df.columns = [
|
|
611
|
+
"基金名称",
|
|
612
|
+
"基金代码",
|
|
613
|
+
"持仓数量",
|
|
614
|
+
"占流通股比例",
|
|
615
|
+
"持股市值",
|
|
616
|
+
"占净值比例",
|
|
617
|
+
"截止日期",
|
|
618
|
+
]
|
|
531
619
|
big_df["持仓数量"] = pd.to_numeric(big_df["持仓数量"], errors="coerce")
|
|
532
620
|
big_df["占流通股比例"] = pd.to_numeric(big_df["占流通股比例"], errors="coerce")
|
|
533
621
|
big_df["持股市值"] = pd.to_numeric(big_df["持股市值"], errors="coerce")
|
|
@@ -551,16 +639,16 @@ def stock_main_stock_holder(stock: str = "600004") -> pd.DataFrame:
|
|
|
551
639
|
temp_df = pd.read_html(StringIO(r.text))[13].iloc[:, :5]
|
|
552
640
|
temp_df.columns = [*range(5)]
|
|
553
641
|
big_df = pd.DataFrame()
|
|
554
|
-
need_range = temp_df[
|
|
555
|
-
|
|
556
|
-
]
|
|
642
|
+
need_range = temp_df[
|
|
643
|
+
temp_df.iloc[:, 0].str.find("截至日期") == 0
|
|
644
|
+
].index.tolist() + [len(temp_df)]
|
|
557
645
|
for i in range(len(need_range) - 1):
|
|
558
646
|
truncated_df = temp_df.iloc[need_range[i] : need_range[i + 1], :]
|
|
559
647
|
truncated_df = truncated_df.dropna(how="all")
|
|
560
648
|
temp_truncated = truncated_df.iloc[5:, :]
|
|
561
649
|
temp_truncated.reset_index(inplace=True, drop=True)
|
|
562
650
|
concat_df = pd.concat(
|
|
563
|
-
[
|
|
651
|
+
objs=[
|
|
564
652
|
temp_truncated,
|
|
565
653
|
truncated_df.iloc[0, :],
|
|
566
654
|
truncated_df.iloc[1, :],
|
|
@@ -578,7 +666,7 @@ def stock_main_stock_holder(stock: str = "600004") -> pd.DataFrame:
|
|
|
578
666
|
concat_df["公告日期"] = concat_df["公告日期"].ffill()
|
|
579
667
|
concat_df["股东总数"] = concat_df["股东总数"].ffill()
|
|
580
668
|
concat_df["平均持股数"] = concat_df["平均持股数"].ffill()
|
|
581
|
-
except
|
|
669
|
+
except: # noqa: E722
|
|
582
670
|
try:
|
|
583
671
|
# try for pandas < 2.1.0
|
|
584
672
|
concat_df["截至日期"] = concat_df["截至日期"].fillna(method="ffill")
|
|
@@ -589,11 +677,15 @@ def stock_main_stock_holder(stock: str = "600004") -> pd.DataFrame:
|
|
|
589
677
|
print("Error:", e)
|
|
590
678
|
|
|
591
679
|
concat_df["股东总数"] = concat_df["股东总数"].str.strip("查看变化趋势")
|
|
592
|
-
concat_df["平均持股数"] = concat_df["平均持股数"].str.strip(
|
|
593
|
-
|
|
680
|
+
concat_df["平均持股数"] = concat_df["平均持股数"].str.strip(
|
|
681
|
+
"(按总股本计算) 查看变化趋势"
|
|
682
|
+
)
|
|
683
|
+
big_df = pd.concat(objs=[big_df, concat_df], axis=0, ignore_index=True)
|
|
594
684
|
big_df.dropna(inplace=True, how="all")
|
|
595
685
|
big_df.reset_index(inplace=True, drop=True)
|
|
596
|
-
big_df.rename(
|
|
686
|
+
big_df.rename(
|
|
687
|
+
columns={"持股数量(股)": "持股数量", "持股比例(%)": "持股比例"}, inplace=True
|
|
688
|
+
)
|
|
597
689
|
big_df.columns.name = None
|
|
598
690
|
big_df["持股数量"] = pd.to_numeric(big_df["持股数量"], errors="coerce")
|
|
599
691
|
big_df["持股比例"] = big_df["持股比例"].str.strip("↓")
|
|
@@ -621,7 +713,7 @@ if __name__ == "__main__":
|
|
|
621
713
|
)
|
|
622
714
|
print(stock_financial_report_sina_df)
|
|
623
715
|
|
|
624
|
-
stock_financial_abstract_df = stock_financial_abstract(symbol="
|
|
716
|
+
stock_financial_abstract_df = stock_financial_abstract(symbol="600600")
|
|
625
717
|
print(stock_financial_abstract_df)
|
|
626
718
|
|
|
627
719
|
stock_financial_analysis_indicator_df = stock_financial_analysis_indicator(
|