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.

Files changed (236) hide show
  1. akshare/__init__.py +441 -138
  2. akshare/air/air_hebei.py +79 -53
  3. akshare/air/air_zhenqi.py +29 -43
  4. akshare/air/sunrise_tad.py +32 -17
  5. akshare/bank/bank_cbirc_2020.py +12 -9
  6. akshare/bond/bond_cb_ths.py +17 -9
  7. akshare/bond/bond_china.py +38 -39
  8. akshare/bond/bond_china_money.py +75 -48
  9. akshare/bond/bond_info_cm.py +28 -8
  10. akshare/bond/bond_issue_cninfo.py +73 -30
  11. akshare/bond/bond_zh_cov.py +1 -1
  12. akshare/bond/bond_zh_sina.py +57 -51
  13. akshare/cal/__init__.py +0 -0
  14. akshare/cal/rv.py +170 -0
  15. akshare/cost/cost_living.py +7 -5
  16. akshare/currency/currency_safe.py +7 -6
  17. akshare/data/cninfo.js +15 -0
  18. akshare/datasets.py +10 -21
  19. akshare/economic/macro_bank.py +95 -653
  20. akshare/economic/macro_china.py +772 -1024
  21. akshare/economic/macro_china_hk.py +65 -243
  22. akshare/economic/macro_china_nbs.py +24 -7
  23. akshare/economic/macro_constitute.py +17 -12
  24. akshare/economic/macro_euro.py +13 -6
  25. akshare/economic/macro_finance_ths.py +133 -0
  26. akshare/economic/macro_info_ws.py +100 -0
  27. akshare/economic/macro_japan.py +5 -4
  28. akshare/economic/macro_other.py +12 -9
  29. akshare/economic/macro_usa.py +376 -1940
  30. akshare/economic/marco_cnbs.py +11 -6
  31. akshare/energy/energy_carbon.py +94 -125
  32. akshare/event/migration.py +3 -2
  33. akshare/exceptions.py +43 -0
  34. akshare/file_fold/calendar.json +245 -2
  35. akshare/fortune/fortune_500.py +15 -48
  36. akshare/fund/fund_amac.py +157 -75
  37. akshare/fund/fund_em.py +191 -184
  38. akshare/fund/fund_etf_em.py +16 -15
  39. akshare/fund/fund_etf_sina.py +71 -23
  40. akshare/fund/fund_etf_ths.py +93 -0
  41. akshare/fund/fund_fee_em.py +98 -0
  42. akshare/fund/fund_portfolio_em.py +60 -50
  43. akshare/fund/fund_rank_em.py +91 -82
  44. akshare/fund/fund_report_cninfo.py +63 -48
  45. akshare/fund/fund_scale_sina.py +20 -10
  46. akshare/fund/fund_xq.py +139 -109
  47. akshare/futures/cons.py +8 -31
  48. akshare/futures/cot.py +185 -137
  49. akshare/futures/futures_basis.py +97 -32
  50. akshare/futures/futures_comm_ctp.py +37 -0
  51. akshare/futures/futures_comm_qihuo.py +74 -45
  52. akshare/futures/futures_daily_bar.py +121 -184
  53. akshare/futures/futures_hf_em.py +66 -61
  54. akshare/futures/futures_hq_sina.py +79 -61
  55. akshare/futures/futures_index_ccidx.py +6 -3
  56. akshare/futures/futures_inventory_99.py +61 -272
  57. akshare/futures/futures_news_shmet.py +4 -2
  58. akshare/futures/futures_roll_yield.py +12 -25
  59. akshare/futures/futures_spot_stock_em.py +19 -13
  60. akshare/futures/futures_stock_js.py +14 -12
  61. akshare/futures/futures_to_spot.py +38 -33
  62. akshare/futures/futures_warehouse_receipt.py +75 -71
  63. akshare/futures/futures_zh_sina.py +5 -5
  64. akshare/futures/symbol_var.py +18 -13
  65. akshare/futures_derivative/futures_contract_info_czce.py +60 -52
  66. akshare/futures_derivative/futures_contract_info_ine.py +43 -34
  67. akshare/futures_derivative/futures_contract_info_shfe.py +46 -35
  68. akshare/futures_derivative/futures_cot_sina.py +26 -19
  69. akshare/futures_derivative/futures_spot_sys.py +21 -8
  70. akshare/fx/currency_investing.py +19 -285
  71. akshare/index/index_cflp.py +29 -26
  72. akshare/index/index_cni.py +86 -88
  73. akshare/index/index_cons.py +26 -10
  74. akshare/index/index_cx.py +248 -47
  75. akshare/index/index_drewry.py +17 -16
  76. akshare/index/index_option_qvix.py +329 -0
  77. akshare/index/index_research_fund_sw.py +134 -0
  78. akshare/index/{index_sw_research.py → index_research_sw.py} +122 -58
  79. akshare/index/index_spot.py +9 -5
  80. akshare/index/index_stock_hk.py +35 -16
  81. akshare/index/index_stock_us_sina.py +1 -1
  82. akshare/index/index_stock_zh.py +180 -89
  83. akshare/index/index_stock_zh_csindex.py +15 -369
  84. akshare/index/index_sw.py +62 -34
  85. akshare/index/index_yw.py +46 -23
  86. akshare/index/index_zh_a_scope.py +48 -0
  87. akshare/index/index_zh_em.py +6 -4
  88. akshare/interest_rate/interbank_rate_em.py +14 -9
  89. akshare/movie/artist_yien.py +32 -5
  90. akshare/movie/movie_yien.py +92 -18
  91. akshare/movie/video_yien.py +28 -5
  92. akshare/news/news_baidu.py +78 -44
  93. akshare/news/news_cctv.py +38 -38
  94. akshare/news/news_stock.py +6 -3
  95. akshare/nlp/nlp_interface.py +7 -8
  96. akshare/option/cons.py +11 -11
  97. akshare/option/option_comm_qihuo.py +86 -0
  98. akshare/option/option_commodity.py +178 -51
  99. akshare/option/option_daily_stats_sse_szse.py +146 -0
  100. akshare/option/option_em.py +147 -138
  101. akshare/option/option_finance_sina.py +160 -137
  102. akshare/option/option_lhb_em.py +62 -56
  103. akshare/option/option_risk_indicator_sse.py +17 -14
  104. akshare/other/other_car_cpca.py +934 -0
  105. akshare/other/{other_car.py → other_car_gasgoo.py} +15 -54
  106. akshare/qdii/__init__.py +0 -0
  107. akshare/qdii/qdii_jsl.py +233 -0
  108. akshare/request.py +117 -0
  109. akshare/spot/spot_hog_soozhu.py +232 -0
  110. akshare/spot/spot_price_qh.py +121 -0
  111. akshare/spot/spot_sge.py +63 -10
  112. akshare/stock/stock_allotment_cninfo.py +10 -9
  113. akshare/stock/stock_board_concept_em.py +23 -14
  114. akshare/stock/stock_board_industry_em.py +40 -34
  115. akshare/stock/stock_cg_equity_mortgage.py +15 -11
  116. akshare/stock/stock_cg_guarantee.py +41 -51
  117. akshare/stock/stock_cg_lawsuit.py +36 -35
  118. akshare/stock/stock_dividend_cninfo.py +12 -6
  119. akshare/stock/stock_dzjy_em.py +347 -260
  120. akshare/stock/stock_fund_em.py +332 -84
  121. akshare/stock/stock_hk_famous.py +108 -0
  122. akshare/stock/stock_hk_sina.py +8 -7
  123. akshare/stock/stock_hold_control_cninfo.py +100 -15
  124. akshare/stock/stock_hold_control_em.py +4 -3
  125. akshare/stock/stock_hold_num_cninfo.py +18 -12
  126. akshare/stock/stock_hot_rank_em.py +2 -1
  127. akshare/stock/stock_hot_search_baidu.py +5 -2
  128. akshare/stock/stock_industry_cninfo.py +24 -18
  129. akshare/stock/stock_industry_pe_cninfo.py +45 -31
  130. akshare/stock/stock_industry_sw.py +9 -10
  131. akshare/stock/stock_info.py +25 -15
  132. akshare/stock/stock_info_em.py +5 -2
  133. akshare/stock/stock_intraday_em.py +5 -2
  134. akshare/stock/stock_intraday_sina.py +22 -18
  135. akshare/stock/stock_ipo_summary_cninfo.py +25 -10
  136. akshare/stock/stock_new_cninfo.py +32 -19
  137. akshare/stock/stock_news_cx.py +39 -0
  138. akshare/stock/stock_profile_cninfo.py +9 -8
  139. akshare/stock/stock_rank_forecast.py +8 -6
  140. akshare/stock/stock_share_changes_cninfo.py +18 -14
  141. akshare/stock/stock_share_hold.py +24 -19
  142. akshare/stock/stock_summary.py +54 -26
  143. akshare/stock/stock_us_famous.py +15 -6
  144. akshare/stock/stock_us_pink.py +7 -5
  145. akshare/stock/stock_us_sina.py +15 -12
  146. akshare/stock/stock_xq.py +38 -12
  147. akshare/stock/stock_zh_a_sina.py +53 -78
  148. akshare/stock/stock_zh_b_sina.py +32 -55
  149. akshare/stock/stock_zh_kcb_report.py +11 -9
  150. akshare/stock/stock_zh_kcb_sina.py +67 -64
  151. akshare/stock_feature/stock_a_below_net_asset_statistics.py +5 -2
  152. akshare/stock_feature/stock_a_high_low.py +5 -2
  153. akshare/stock_feature/stock_a_indicator.py +12 -9
  154. akshare/stock_feature/stock_a_pe_and_pb.py +27 -6
  155. akshare/stock_feature/stock_account_em.py +58 -40
  156. akshare/stock_feature/stock_analyst_em.py +36 -27
  157. akshare/stock_feature/stock_board_industry_ths.py +136 -400
  158. akshare/stock_feature/stock_comment_em.py +118 -85
  159. akshare/stock_feature/stock_concept_futu.py +183 -0
  160. akshare/stock_feature/stock_cyq_em.py +58 -54
  161. akshare/stock_feature/stock_disclosure_cninfo.py +147 -102
  162. akshare/stock_feature/stock_esg_sina.py +216 -11
  163. akshare/stock_feature/stock_fhps_em.py +60 -25
  164. akshare/stock_feature/stock_fhps_ths.py +25 -6
  165. akshare/stock_feature/stock_fund_flow.py +38 -25
  166. akshare/stock_feature/stock_gdfx_em.py +180 -95
  167. akshare/stock_feature/stock_gdhs.py +73 -49
  168. akshare/stock_feature/stock_gpzy_em.py +78 -46
  169. akshare/stock_feature/stock_hist_em.py +55 -23
  170. akshare/stock_feature/stock_hk_valuation_baidu.py +20 -8
  171. akshare/stock_feature/stock_hsgt_em.py +184 -452
  172. akshare/stock_feature/stock_info.py +52 -29
  173. akshare/stock_feature/stock_inner_trade_xq.py +39 -31
  174. akshare/stock_feature/stock_irm_cninfo.py +32 -9
  175. akshare/stock_feature/stock_jgdy_em.py +41 -38
  176. akshare/stock_feature/stock_lh_yybpm.py +36 -37
  177. akshare/stock_feature/stock_lhb_em.py +135 -71
  178. akshare/stock_feature/stock_lhb_sina.py +93 -46
  179. akshare/stock_feature/stock_margin_em.py +102 -0
  180. akshare/stock_feature/{stock_sse_margin.py → stock_margin_sse.py} +21 -15
  181. akshare/stock_feature/{stock_szse_margin.py → stock_margin_szse.py} +23 -19
  182. akshare/stock_feature/stock_market_legu.py +13 -8
  183. akshare/stock_feature/stock_pankou_em.py +72 -34
  184. akshare/stock_feature/stock_report_em.py +244 -54
  185. akshare/stock_feature/stock_research_report_em.py +48 -19
  186. akshare/stock_feature/stock_sns_sseinfo.py +15 -12
  187. akshare/stock_feature/stock_sy_em.py +86 -33
  188. akshare/stock_feature/stock_technology_ths.py +152 -120
  189. akshare/stock_feature/stock_tfp_em.py +35 -13
  190. akshare/stock_feature/stock_three_report_em.py +119 -77
  191. akshare/stock_feature/stock_ttm_lyr.py +4 -7
  192. akshare/stock_feature/stock_value_em.py +83 -0
  193. akshare/stock_feature/stock_wencai.py +21 -9
  194. akshare/stock_feature/stock_yjyg_em.py +63 -28
  195. akshare/stock_feature/stock_zf_pg.py +61 -38
  196. akshare/stock_feature/stock_zh_valuation_baidu.py +3 -2
  197. akshare/stock_feature/stock_ztb_em.py +62 -40
  198. akshare/stock_fundamental/stock_finance.py +150 -58
  199. akshare/stock_fundamental/stock_finance_ths.py +116 -31
  200. akshare/stock_fundamental/stock_mda_ym.py +5 -3
  201. akshare/stock_fundamental/stock_notice.py +29 -15
  202. akshare/stock_fundamental/stock_profit_forecast_em.py +31 -13
  203. akshare/stock_fundamental/stock_profit_forecast_ths.py +19 -10
  204. akshare/stock_fundamental/stock_register_em.py +448 -0
  205. akshare/stock_fundamental/stock_restricted_em.py +79 -32
  206. akshare/stock_fundamental/stock_zygc.py +10 -8
  207. akshare/stock_fundamental/stock_zyjs_ths.py +5 -3
  208. akshare/tool/trade_date_hist.py +4 -3
  209. akshare/utils/cons.py +10 -0
  210. akshare/utils/context.py +43 -0
  211. akshare/utils/demjson.py +2 -2
  212. akshare/utils/func.py +26 -0
  213. akshare/utils/tqdm.py +13 -3
  214. {akshare-1.12.99.dist-info → akshare-1.15.72.dist-info}/METADATA +52 -69
  215. akshare-1.15.72.dist-info/RECORD +385 -0
  216. {akshare-1.12.99.dist-info → akshare-1.15.72.dist-info}/WHEEL +1 -1
  217. tests/test_func.py +3 -5
  218. akshare/bond/bond_futures.py +0 -50
  219. akshare/bond/bond_investing.py +0 -139
  220. akshare/crypto/crypto_hist_investing.py +0 -249
  221. akshare/fortune/fortune_it_juzi.py +0 -123
  222. akshare/futures/futures_international.py +0 -170
  223. akshare/futures/futures_news_baidu.py +0 -54
  224. akshare/futures/inventory_data.py +0 -100
  225. akshare/futures_derivative/futures_index_price_nh.py +0 -61
  226. akshare/futures_derivative/futures_index_return_nh.py +0 -47
  227. akshare/futures_derivative/futures_index_volatility_nh.py +0 -51
  228. akshare/futures_derivative/futures_other_index_nh.py +0 -145
  229. akshare/index/index_fear_greed_funddb.py +0 -71
  230. akshare/index/index_investing.py +0 -232
  231. akshare/sport/sport_olympic_winter.py +0 -39
  232. akshare/stock_feature/stock_board_concept_ths.py +0 -422
  233. akshare/stock_fundamental/stock_register.py +0 -292
  234. akshare-1.12.99.dist-info/RECORD +0 -374
  235. {akshare-1.12.99.dist-info → akshare-1.15.72.dist-info}/LICENSE +0 -0
  236. {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: 2023/9/2 19:00
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
- from tqdm import tqdm
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": "100",
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]["rCurrency"],
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": "100",
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([big_df, temp_df["item_value"]], axis=1, ignore_index=True)
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 = f"https://money.finance.sina.com.cn/corp/go.php/vFD_FinancialGuideLine/stockid/{symbol}/ctrl/2020/displaytype/4.phtml"
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 = f"https://money.finance.sina.com.cn/corp/go.php/vFD_FinancialGuideLine/stockid/{symbol}/ctrl/{year_item}/displaytype/4.phtml"
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[temp_df.iloc[:, 0].str.find(indicator_list[i]) == 0, :]
214
- .index[0] : temp_df.loc[
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
- http://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/lsfh/index.phtml?p=1&num=5000
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 = "http://vip.stock.finance.sina.com.cn/q/go.php/vInvestConsult/kind/lsfh/index.phtml"
241
- params = {"p": "1", "num": "5000"}
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"http://vip.stock.finance.sina.com.cn/corp/go.php/vISSUE_ShareBonus/stockid/{symbol}.phtml"
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(temp_df["公告日期"], errors="coerce").dt.date
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"http://vip.stock.finance.sina.com.cn/corp/go.php/vISSUE_ShareBonus/stockid/{symbol}.phtml"
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(temp_df["公告日期"], errors="coerce").dt.date
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(temp_df["募集资金合计"], errors="coerce")
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
- big_df['公告日期'] = pd.to_datetime(big_df['公告日期'], errors="coerce").dt.date
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(temp_df["解禁股流通市值"], errors="coerce")
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[temp_df.iloc[:, 0].str.find("截止日期") == 0].index.tolist() + [
452
- len(temp_df)
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, :]], axis=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 Exception as e:
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
- big_df.columns = ["截止日期", "公告日期", "编号", "股东名称", "持股数量", "占流通股比例", "股本性质"]
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[temp_df.iloc[:, 0].str.find("截止日期") == 0].index.tolist() + [
505
- len(temp_df)
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 Exception as e:
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[temp_df.iloc[:, 0].str.find("截至日期") == 0].index.tolist() + [
555
- len(temp_df)
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 Exception as e:
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
- big_df = pd.concat([big_df, concat_df], axis=0, ignore_index=True)
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(columns={"持股数量(股)": "持股数量", "持股比例(%)": "持股比例"}, inplace=True)
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="600004")
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(