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
|
@@ -0,0 +1,934 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding:utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Date: 2024/8/3 20:00
|
|
5
|
+
Desc: 乘联会
|
|
6
|
+
http://data.cpcadata.com/FuelMarket
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import pandas as pd
|
|
10
|
+
import requests
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def car_market_total_cpca(
|
|
14
|
+
symbol: str = "狭义乘用车", indicator: str = "产量"
|
|
15
|
+
) -> pd.DataFrame:
|
|
16
|
+
"""
|
|
17
|
+
乘联会-统计数据-总体市场
|
|
18
|
+
http://data.cpcadata.com/TotalMarket
|
|
19
|
+
:param symbol: choice of {"狭义乘用车", "广义乘用车"}
|
|
20
|
+
:type symbol: str
|
|
21
|
+
:param indicator: choice of {"产量", "批发", "零售", "出口"}
|
|
22
|
+
:type indicator: str
|
|
23
|
+
:return: 统计数据-总体市场
|
|
24
|
+
:rtype: pandas.DataFrame
|
|
25
|
+
"""
|
|
26
|
+
url = "http://data.cpcadata.com/api/chartlist"
|
|
27
|
+
params = {"charttype": "1"}
|
|
28
|
+
r = requests.get(url, params=params)
|
|
29
|
+
data_json = r.json()
|
|
30
|
+
big_df = pd.DataFrame()
|
|
31
|
+
if symbol == "狭义乘用车":
|
|
32
|
+
temp_df = pd.DataFrame(data_json[0]["dataList"])
|
|
33
|
+
temp_current_year_list = []
|
|
34
|
+
temp_previous_year_list = []
|
|
35
|
+
for item in data_json[0]["dataList"]:
|
|
36
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
37
|
+
try:
|
|
38
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
39
|
+
except: # noqa: E722
|
|
40
|
+
continue
|
|
41
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
42
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
43
|
+
if indicator == "产量":
|
|
44
|
+
big_df = pd.DataFrame(
|
|
45
|
+
[temp_current_year_df.iloc[:, 0], temp_previous_year_df.iloc[:, 0]]
|
|
46
|
+
).T
|
|
47
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
48
|
+
big_df["月份"] = temp_df["month"]
|
|
49
|
+
big_df = big_df[
|
|
50
|
+
[
|
|
51
|
+
"月份",
|
|
52
|
+
temp_df.columns[2],
|
|
53
|
+
temp_df.columns[1],
|
|
54
|
+
]
|
|
55
|
+
]
|
|
56
|
+
elif indicator == "批发":
|
|
57
|
+
big_df = pd.DataFrame(
|
|
58
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
59
|
+
).T
|
|
60
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
61
|
+
big_df["月份"] = temp_df["month"]
|
|
62
|
+
big_df = big_df[
|
|
63
|
+
[
|
|
64
|
+
"月份",
|
|
65
|
+
temp_df.columns[2],
|
|
66
|
+
temp_df.columns[1],
|
|
67
|
+
]
|
|
68
|
+
]
|
|
69
|
+
elif indicator == "零售":
|
|
70
|
+
big_df = pd.DataFrame(
|
|
71
|
+
[temp_current_year_df.iloc[:, 2], temp_previous_year_df.iloc[:, 2]]
|
|
72
|
+
).T
|
|
73
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
74
|
+
big_df["月份"] = temp_df["month"]
|
|
75
|
+
big_df = big_df[
|
|
76
|
+
[
|
|
77
|
+
"月份",
|
|
78
|
+
temp_df.columns[2],
|
|
79
|
+
temp_df.columns[1],
|
|
80
|
+
]
|
|
81
|
+
]
|
|
82
|
+
elif indicator == "出口":
|
|
83
|
+
big_df = pd.DataFrame(
|
|
84
|
+
[temp_current_year_df.iloc[:, 3], temp_previous_year_df.iloc[:, 3]]
|
|
85
|
+
).T
|
|
86
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
87
|
+
big_df["月份"] = temp_df["month"]
|
|
88
|
+
big_df = big_df[
|
|
89
|
+
[
|
|
90
|
+
"月份",
|
|
91
|
+
temp_df.columns[2],
|
|
92
|
+
temp_df.columns[1],
|
|
93
|
+
]
|
|
94
|
+
]
|
|
95
|
+
else:
|
|
96
|
+
temp_df = pd.DataFrame(data_json[1]["dataList"])
|
|
97
|
+
temp_current_year_list = []
|
|
98
|
+
temp_previous_year_list = []
|
|
99
|
+
for item in data_json[1]["dataList"]:
|
|
100
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
101
|
+
try:
|
|
102
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
103
|
+
except: # noqa: E722
|
|
104
|
+
continue
|
|
105
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
106
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
107
|
+
if indicator == "产量":
|
|
108
|
+
big_df = pd.DataFrame(
|
|
109
|
+
[temp_current_year_df.iloc[:, 0], temp_previous_year_df.iloc[:, 0]]
|
|
110
|
+
).T
|
|
111
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
112
|
+
big_df["月份"] = temp_df["month"]
|
|
113
|
+
big_df = big_df[
|
|
114
|
+
[
|
|
115
|
+
"月份",
|
|
116
|
+
temp_df.columns[2],
|
|
117
|
+
temp_df.columns[1],
|
|
118
|
+
]
|
|
119
|
+
]
|
|
120
|
+
elif indicator == "批发":
|
|
121
|
+
big_df = pd.DataFrame(
|
|
122
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
123
|
+
).T
|
|
124
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
125
|
+
big_df["月份"] = temp_df["month"]
|
|
126
|
+
big_df = big_df[
|
|
127
|
+
[
|
|
128
|
+
"月份",
|
|
129
|
+
temp_df.columns[2],
|
|
130
|
+
temp_df.columns[1],
|
|
131
|
+
]
|
|
132
|
+
]
|
|
133
|
+
elif indicator == "零售":
|
|
134
|
+
big_df = pd.DataFrame(
|
|
135
|
+
[temp_current_year_df.iloc[:, 2], temp_previous_year_df.iloc[:, 2]]
|
|
136
|
+
).T
|
|
137
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
138
|
+
big_df["月份"] = temp_df["month"]
|
|
139
|
+
big_df = big_df[
|
|
140
|
+
[
|
|
141
|
+
"月份",
|
|
142
|
+
temp_df.columns[2],
|
|
143
|
+
temp_df.columns[1],
|
|
144
|
+
]
|
|
145
|
+
]
|
|
146
|
+
elif indicator == "出口":
|
|
147
|
+
big_df = pd.DataFrame(
|
|
148
|
+
[temp_current_year_df.iloc[:, 3], temp_previous_year_df.iloc[:, 3]]
|
|
149
|
+
).T
|
|
150
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
151
|
+
big_df["月份"] = temp_df["month"]
|
|
152
|
+
big_df = big_df[
|
|
153
|
+
[
|
|
154
|
+
"月份",
|
|
155
|
+
temp_df.columns[2],
|
|
156
|
+
temp_df.columns[1],
|
|
157
|
+
]
|
|
158
|
+
]
|
|
159
|
+
|
|
160
|
+
return big_df
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def __car_market_man_rank_cpca_pifa(symbol: str = "狭义乘用车-累计") -> pd.DataFrame:
|
|
164
|
+
"""
|
|
165
|
+
乘联会-统计数据-厂商排名
|
|
166
|
+
http://data.cpcadata.com/ManRank
|
|
167
|
+
:param symbol: choice of {"狭义乘用车-单月", "狭义乘用车-累计", "广义乘用车-单月", "广义乘用车-累计"}
|
|
168
|
+
:type symbol: str
|
|
169
|
+
:return: 统计数据-厂商排名
|
|
170
|
+
:rtype: pandas.DataFrame
|
|
171
|
+
"""
|
|
172
|
+
url = "http://data.cpcadata.com/api/chartlist"
|
|
173
|
+
params = {"charttype": "2"}
|
|
174
|
+
r = requests.get(url, params=params)
|
|
175
|
+
data_json = r.json()
|
|
176
|
+
big_df = pd.DataFrame()
|
|
177
|
+
if symbol == "狭义乘用车-累计":
|
|
178
|
+
temp_df = pd.DataFrame(data_json[0]["dataList"])
|
|
179
|
+
temp_current_year_list = []
|
|
180
|
+
temp_previous_year_list = []
|
|
181
|
+
for item in data_json[0]["dataList"]:
|
|
182
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
183
|
+
try:
|
|
184
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
185
|
+
except: # noqa: E722
|
|
186
|
+
continue
|
|
187
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
188
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
189
|
+
big_df = pd.DataFrame(
|
|
190
|
+
[temp_current_year_df.iloc[:, 0], temp_previous_year_df.iloc[:, 0]]
|
|
191
|
+
).T
|
|
192
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
193
|
+
big_df["厂商"] = temp_df["厂商"]
|
|
194
|
+
big_df = big_df[
|
|
195
|
+
[
|
|
196
|
+
"厂商",
|
|
197
|
+
temp_df.columns[2],
|
|
198
|
+
temp_df.columns[1],
|
|
199
|
+
]
|
|
200
|
+
]
|
|
201
|
+
elif symbol == "狭义乘用车-单月":
|
|
202
|
+
temp_df = pd.DataFrame(data_json[1]["dataList"])
|
|
203
|
+
temp_current_year_list = []
|
|
204
|
+
temp_previous_year_list = []
|
|
205
|
+
for item in data_json[1]["dataList"]:
|
|
206
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
207
|
+
try:
|
|
208
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
209
|
+
except: # noqa: E722
|
|
210
|
+
continue
|
|
211
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
212
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
213
|
+
big_df = pd.DataFrame(
|
|
214
|
+
[temp_current_year_df.iloc[:, 0], temp_previous_year_df.iloc[:, 0]]
|
|
215
|
+
).T
|
|
216
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
217
|
+
big_df["厂商"] = temp_df["厂商"]
|
|
218
|
+
big_df = big_df[
|
|
219
|
+
[
|
|
220
|
+
"厂商",
|
|
221
|
+
temp_df.columns[2],
|
|
222
|
+
temp_df.columns[1],
|
|
223
|
+
]
|
|
224
|
+
]
|
|
225
|
+
elif symbol == "广义乘用车-累计":
|
|
226
|
+
temp_df = pd.DataFrame(data_json[2]["dataList"])
|
|
227
|
+
temp_current_year_list = []
|
|
228
|
+
temp_previous_year_list = []
|
|
229
|
+
for item in data_json[2]["dataList"]:
|
|
230
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
231
|
+
try:
|
|
232
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
233
|
+
except: # noqa: E722
|
|
234
|
+
continue
|
|
235
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
236
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
237
|
+
big_df = pd.DataFrame(
|
|
238
|
+
[temp_current_year_df.iloc[:, 0], temp_previous_year_df.iloc[:, 0]]
|
|
239
|
+
).T
|
|
240
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
241
|
+
big_df["厂商"] = temp_df["厂商"]
|
|
242
|
+
big_df = big_df[
|
|
243
|
+
[
|
|
244
|
+
"厂商",
|
|
245
|
+
temp_df.columns[2],
|
|
246
|
+
temp_df.columns[1],
|
|
247
|
+
]
|
|
248
|
+
]
|
|
249
|
+
elif symbol == "广义乘用车-单月":
|
|
250
|
+
temp_df = pd.DataFrame(data_json[3]["dataList"])
|
|
251
|
+
temp_current_year_list = []
|
|
252
|
+
temp_previous_year_list = []
|
|
253
|
+
for item in data_json[3]["dataList"]:
|
|
254
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
255
|
+
try:
|
|
256
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
257
|
+
except: # noqa: E722
|
|
258
|
+
continue
|
|
259
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
260
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
261
|
+
big_df = pd.DataFrame(
|
|
262
|
+
[temp_current_year_df.iloc[:, 0], temp_previous_year_df.iloc[:, 0]]
|
|
263
|
+
).T
|
|
264
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
265
|
+
big_df["厂商"] = temp_df["厂商"]
|
|
266
|
+
big_df = big_df[
|
|
267
|
+
[
|
|
268
|
+
"厂商",
|
|
269
|
+
temp_df.columns[2],
|
|
270
|
+
temp_df.columns[1],
|
|
271
|
+
]
|
|
272
|
+
]
|
|
273
|
+
return big_df
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def __car_market_man_rank_cpca_lingshou(
|
|
277
|
+
symbol: str = "狭义乘用车-累计",
|
|
278
|
+
) -> pd.DataFrame:
|
|
279
|
+
"""
|
|
280
|
+
乘联会-统计数据-厂商排名
|
|
281
|
+
http://data.cpcadata.com/ManRank
|
|
282
|
+
:param symbol: choice of {"狭义乘用车-单月", "狭义乘用车-累计", "广义乘用车-单月", "广义乘用车-累计"}
|
|
283
|
+
:type symbol: str
|
|
284
|
+
:return: 统计数据-厂商排名
|
|
285
|
+
:rtype: pandas.DataFrame
|
|
286
|
+
"""
|
|
287
|
+
url = "http://data.cpcadata.com/api/chartlist_2"
|
|
288
|
+
params = {"charttype": "2"}
|
|
289
|
+
r = requests.get(url, params=params)
|
|
290
|
+
data_json = r.json()
|
|
291
|
+
big_df = pd.DataFrame()
|
|
292
|
+
if symbol == "狭义乘用车-累计":
|
|
293
|
+
temp_df = pd.DataFrame(data_json[0]["dataList"])
|
|
294
|
+
temp_current_year_list = []
|
|
295
|
+
temp_previous_year_list = []
|
|
296
|
+
for item in data_json[0]["dataList"]:
|
|
297
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
298
|
+
try:
|
|
299
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
300
|
+
except: # noqa: E722
|
|
301
|
+
continue
|
|
302
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
303
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
304
|
+
big_df = pd.DataFrame(
|
|
305
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
306
|
+
).T
|
|
307
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
308
|
+
big_df["厂商"] = temp_df["厂商"]
|
|
309
|
+
big_df = big_df[
|
|
310
|
+
[
|
|
311
|
+
"厂商",
|
|
312
|
+
temp_df.columns[2],
|
|
313
|
+
temp_df.columns[1],
|
|
314
|
+
]
|
|
315
|
+
]
|
|
316
|
+
elif symbol == "狭义乘用车-单月":
|
|
317
|
+
temp_df = pd.DataFrame(data_json[1]["dataList"])
|
|
318
|
+
temp_current_year_list = []
|
|
319
|
+
temp_previous_year_list = []
|
|
320
|
+
for item in data_json[1]["dataList"]:
|
|
321
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
322
|
+
try:
|
|
323
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
324
|
+
except: # noqa: E722
|
|
325
|
+
continue
|
|
326
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
327
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
328
|
+
big_df = pd.DataFrame(
|
|
329
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
330
|
+
).T
|
|
331
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
332
|
+
big_df["厂商"] = temp_df["厂商"]
|
|
333
|
+
big_df = big_df[
|
|
334
|
+
[
|
|
335
|
+
"厂商",
|
|
336
|
+
temp_df.columns[2],
|
|
337
|
+
temp_df.columns[1],
|
|
338
|
+
]
|
|
339
|
+
]
|
|
340
|
+
elif symbol == "广义乘用车-累计":
|
|
341
|
+
temp_df = pd.DataFrame(data_json[2]["dataList"])
|
|
342
|
+
temp_current_year_list = []
|
|
343
|
+
temp_previous_year_list = []
|
|
344
|
+
for item in data_json[2]["dataList"]:
|
|
345
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
346
|
+
try:
|
|
347
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
348
|
+
except: # noqa: E722
|
|
349
|
+
continue
|
|
350
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
351
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
352
|
+
big_df = pd.DataFrame(
|
|
353
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
354
|
+
).T
|
|
355
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
356
|
+
big_df["厂商"] = temp_df["厂商"]
|
|
357
|
+
big_df = big_df[
|
|
358
|
+
[
|
|
359
|
+
"厂商",
|
|
360
|
+
temp_df.columns[2],
|
|
361
|
+
temp_df.columns[1],
|
|
362
|
+
]
|
|
363
|
+
]
|
|
364
|
+
elif symbol == "广义乘用车-单月":
|
|
365
|
+
temp_df = pd.DataFrame(data_json[3]["dataList"])
|
|
366
|
+
temp_current_year_list = []
|
|
367
|
+
temp_previous_year_list = []
|
|
368
|
+
for item in data_json[3]["dataList"]:
|
|
369
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
370
|
+
try:
|
|
371
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
372
|
+
except: # noqa: E722
|
|
373
|
+
continue
|
|
374
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
375
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
376
|
+
big_df = pd.DataFrame(
|
|
377
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
378
|
+
).T
|
|
379
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
380
|
+
big_df["厂商"] = temp_df["厂商"]
|
|
381
|
+
big_df = big_df[
|
|
382
|
+
[
|
|
383
|
+
"厂商",
|
|
384
|
+
temp_df.columns[2],
|
|
385
|
+
temp_df.columns[1],
|
|
386
|
+
]
|
|
387
|
+
]
|
|
388
|
+
return big_df
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def car_market_man_rank_cpca(
|
|
392
|
+
symbol: str = "狭义乘用车-单月", indicator: str = "批发"
|
|
393
|
+
) -> pd.DataFrame:
|
|
394
|
+
"""
|
|
395
|
+
乘联会-统计数据-厂商排名
|
|
396
|
+
http://data.cpcadata.com/ManRank
|
|
397
|
+
:param symbol: choice of {"狭义乘用车-单月", "狭义乘用车-累计", "广义乘用车-单月", "广义乘用车-累计"}
|
|
398
|
+
:type symbol: str
|
|
399
|
+
:param indicator: choice of {"批发", "零售"}
|
|
400
|
+
:type indicator: str
|
|
401
|
+
:return: 统计数据-厂商排名
|
|
402
|
+
:rtype: pandas.DataFrame
|
|
403
|
+
"""
|
|
404
|
+
if indicator == "批发":
|
|
405
|
+
temp_df = __car_market_man_rank_cpca_pifa(symbol=symbol)
|
|
406
|
+
return temp_df
|
|
407
|
+
else:
|
|
408
|
+
temp_df = __car_market_man_rank_cpca_lingshou(symbol=symbol)
|
|
409
|
+
return temp_df
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def __car_market_cate_cpca_pifa(symbol: str = "MPV") -> pd.DataFrame:
|
|
413
|
+
"""
|
|
414
|
+
乘联会-统计数据-车型大类
|
|
415
|
+
http://data.cpcadata.com/CategoryMarket
|
|
416
|
+
:param symbol: choice of {"轿车", "MPV", "SUV", "占比"}
|
|
417
|
+
:type symbol: str
|
|
418
|
+
:return: 统计数据-车型大类
|
|
419
|
+
:rtype: pandas.DataFrame
|
|
420
|
+
"""
|
|
421
|
+
url = "http://data.cpcadata.com/api/chartlist"
|
|
422
|
+
params = {"charttype": "3"}
|
|
423
|
+
r = requests.get(url, params=params)
|
|
424
|
+
data_json = r.json()
|
|
425
|
+
big_df = pd.DataFrame()
|
|
426
|
+
if symbol == "MPV":
|
|
427
|
+
temp_df = pd.DataFrame(data_json[0]["dataList"])
|
|
428
|
+
temp_current_year_list = []
|
|
429
|
+
temp_previous_year_list = []
|
|
430
|
+
for item in data_json[0]["dataList"]:
|
|
431
|
+
temp_previous_year_list.append(item[temp_df.columns[1]])
|
|
432
|
+
try:
|
|
433
|
+
temp_current_year_list.append(item[temp_df.columns[2]])
|
|
434
|
+
except: # noqa: E722
|
|
435
|
+
continue
|
|
436
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
437
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
438
|
+
big_df = pd.DataFrame(
|
|
439
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
440
|
+
).T
|
|
441
|
+
big_df.columns = [temp_df.columns[2], temp_df.columns[1]]
|
|
442
|
+
big_df["月份"] = temp_df["month"]
|
|
443
|
+
big_df = big_df[
|
|
444
|
+
[
|
|
445
|
+
"月份",
|
|
446
|
+
temp_df.columns[2],
|
|
447
|
+
temp_df.columns[1],
|
|
448
|
+
]
|
|
449
|
+
]
|
|
450
|
+
elif symbol == "SUV":
|
|
451
|
+
temp_df = pd.DataFrame(data_json[1]["dataList"])
|
|
452
|
+
temp_current_year_list = []
|
|
453
|
+
temp_previous_year_list = []
|
|
454
|
+
for item in data_json[1]["dataList"]:
|
|
455
|
+
temp_previous_year_list.append(item[temp_df.columns[1]])
|
|
456
|
+
try:
|
|
457
|
+
temp_current_year_list.append(item[temp_df.columns[2]])
|
|
458
|
+
except: # noqa: E722
|
|
459
|
+
continue
|
|
460
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
461
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
462
|
+
big_df = pd.DataFrame(
|
|
463
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
464
|
+
).T
|
|
465
|
+
big_df.columns = [temp_df.columns[2], temp_df.columns[1]]
|
|
466
|
+
big_df["月份"] = temp_df["month"]
|
|
467
|
+
big_df = big_df[
|
|
468
|
+
[
|
|
469
|
+
"月份",
|
|
470
|
+
temp_df.columns[2],
|
|
471
|
+
temp_df.columns[1],
|
|
472
|
+
]
|
|
473
|
+
]
|
|
474
|
+
elif symbol == "轿车":
|
|
475
|
+
temp_df = pd.DataFrame(data_json[2]["dataList"])
|
|
476
|
+
temp_current_year_list = []
|
|
477
|
+
temp_previous_year_list = []
|
|
478
|
+
for item in data_json[2]["dataList"]:
|
|
479
|
+
temp_previous_year_list.append(item[temp_df.columns[1]])
|
|
480
|
+
try:
|
|
481
|
+
temp_current_year_list.append(item[temp_df.columns[2]])
|
|
482
|
+
except: # noqa: E722
|
|
483
|
+
continue
|
|
484
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
485
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
486
|
+
big_df = pd.DataFrame(
|
|
487
|
+
[temp_current_year_df.iloc[:, 1], temp_previous_year_df.iloc[:, 1]]
|
|
488
|
+
).T
|
|
489
|
+
big_df.columns = [temp_df.columns[2], temp_df.columns[1]]
|
|
490
|
+
big_df["月份"] = temp_df["month"]
|
|
491
|
+
big_df = big_df[
|
|
492
|
+
[
|
|
493
|
+
"月份",
|
|
494
|
+
temp_df.columns[1],
|
|
495
|
+
temp_df.columns[2],
|
|
496
|
+
]
|
|
497
|
+
]
|
|
498
|
+
elif symbol == "占比":
|
|
499
|
+
temp_df = pd.DataFrame(data_json[3]["dataList"])
|
|
500
|
+
temp_mpv_year_list = []
|
|
501
|
+
temp_suv_year_list = []
|
|
502
|
+
temp_jiaoche_year_list = []
|
|
503
|
+
for item in data_json[3]["dataList"]:
|
|
504
|
+
temp_mpv_year_list.append(item[temp_df.columns[1]])
|
|
505
|
+
try:
|
|
506
|
+
temp_suv_year_list.append(item[temp_df.columns[2]])
|
|
507
|
+
temp_jiaoche_year_list.append(item[temp_df.columns[3]])
|
|
508
|
+
except: # noqa: E722
|
|
509
|
+
continue
|
|
510
|
+
temp_mpv_year_df = pd.DataFrame(temp_mpv_year_list)
|
|
511
|
+
temp_suv_year_df = pd.DataFrame(temp_suv_year_list)
|
|
512
|
+
temp_jiaoche_year_df = pd.DataFrame(temp_jiaoche_year_list)
|
|
513
|
+
big_df = pd.DataFrame(
|
|
514
|
+
[
|
|
515
|
+
temp_mpv_year_df.iloc[:, 2],
|
|
516
|
+
temp_suv_year_df.iloc[:, 2],
|
|
517
|
+
temp_jiaoche_year_df.iloc[:, 2],
|
|
518
|
+
]
|
|
519
|
+
).T
|
|
520
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2], temp_df.columns[3]]
|
|
521
|
+
big_df["月份"] = temp_df["月份"]
|
|
522
|
+
big_df = big_df[
|
|
523
|
+
["月份", temp_df.columns[1], temp_df.columns[2], temp_df.columns[3]]
|
|
524
|
+
]
|
|
525
|
+
return big_df
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def __car_market_cate_cpca_lingshou(
|
|
529
|
+
symbol: str = "狭义乘用车-累计",
|
|
530
|
+
) -> pd.DataFrame:
|
|
531
|
+
"""
|
|
532
|
+
乘联会-统计数据-车型大类
|
|
533
|
+
http://data.cpcadata.com/CategoryMarket
|
|
534
|
+
:param symbol: choice of {"轿车", "MPV", "SUV", "占比"}
|
|
535
|
+
:type symbol: str
|
|
536
|
+
:return: 统计数据-车型大类
|
|
537
|
+
:rtype: pandas.DataFrame
|
|
538
|
+
"""
|
|
539
|
+
url = "http://data.cpcadata.com/api/chartlist"
|
|
540
|
+
params = {"charttype": "3"}
|
|
541
|
+
r = requests.get(url, params=params)
|
|
542
|
+
data_json = r.json()
|
|
543
|
+
big_df = pd.DataFrame()
|
|
544
|
+
if symbol == "MPV":
|
|
545
|
+
temp_df = pd.DataFrame(data_json[0]["dataList"])
|
|
546
|
+
temp_current_year_list = []
|
|
547
|
+
temp_previous_year_list = []
|
|
548
|
+
for item in data_json[0]["dataList"]:
|
|
549
|
+
temp_previous_year_list.append(item[temp_df.columns[1]])
|
|
550
|
+
try:
|
|
551
|
+
temp_current_year_list.append(item[temp_df.columns[2]])
|
|
552
|
+
except: # noqa: E722
|
|
553
|
+
continue
|
|
554
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
555
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
556
|
+
big_df = pd.DataFrame(
|
|
557
|
+
[temp_current_year_df.iloc[:, 2], temp_previous_year_df.iloc[:, 2]]
|
|
558
|
+
).T
|
|
559
|
+
big_df.columns = [temp_df.columns[2], temp_df.columns[1]]
|
|
560
|
+
big_df["月份"] = temp_df["month"]
|
|
561
|
+
big_df = big_df[
|
|
562
|
+
[
|
|
563
|
+
"月份",
|
|
564
|
+
temp_df.columns[2],
|
|
565
|
+
temp_df.columns[1],
|
|
566
|
+
]
|
|
567
|
+
]
|
|
568
|
+
elif symbol == "SUV":
|
|
569
|
+
temp_df = pd.DataFrame(data_json[1]["dataList"])
|
|
570
|
+
temp_current_year_list = []
|
|
571
|
+
temp_previous_year_list = []
|
|
572
|
+
for item in data_json[1]["dataList"]:
|
|
573
|
+
temp_previous_year_list.append(item[temp_df.columns[1]])
|
|
574
|
+
try:
|
|
575
|
+
temp_current_year_list.append(item[temp_df.columns[2]])
|
|
576
|
+
except: # noqa: E722
|
|
577
|
+
continue
|
|
578
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
579
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
580
|
+
big_df = pd.DataFrame(
|
|
581
|
+
[temp_current_year_df.iloc[:, 2], temp_previous_year_df.iloc[:, 2]]
|
|
582
|
+
).T
|
|
583
|
+
big_df.columns = [temp_df.columns[2], temp_df.columns[1]]
|
|
584
|
+
big_df["月份"] = temp_df["month"]
|
|
585
|
+
big_df = big_df[
|
|
586
|
+
[
|
|
587
|
+
"月份",
|
|
588
|
+
temp_df.columns[2],
|
|
589
|
+
temp_df.columns[1],
|
|
590
|
+
]
|
|
591
|
+
]
|
|
592
|
+
elif symbol == "轿车":
|
|
593
|
+
temp_df = pd.DataFrame(data_json[2]["dataList"])
|
|
594
|
+
temp_current_year_list = []
|
|
595
|
+
temp_previous_year_list = []
|
|
596
|
+
for item in data_json[2]["dataList"]:
|
|
597
|
+
temp_previous_year_list.append(item[temp_df.columns[1]])
|
|
598
|
+
try:
|
|
599
|
+
temp_current_year_list.append(item[temp_df.columns[2]])
|
|
600
|
+
except: # noqa: E722
|
|
601
|
+
continue
|
|
602
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
603
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
604
|
+
big_df = pd.DataFrame(
|
|
605
|
+
[temp_current_year_df.iloc[:, 2], temp_previous_year_df.iloc[:, 2]]
|
|
606
|
+
).T
|
|
607
|
+
big_df.columns = [temp_df.columns[2], temp_df.columns[1]]
|
|
608
|
+
big_df["月份"] = temp_df["month"]
|
|
609
|
+
big_df = big_df[
|
|
610
|
+
[
|
|
611
|
+
"月份",
|
|
612
|
+
temp_df.columns[2],
|
|
613
|
+
temp_df.columns[1],
|
|
614
|
+
]
|
|
615
|
+
]
|
|
616
|
+
elif symbol == "占比":
|
|
617
|
+
temp_df = pd.DataFrame(data_json[3]["dataList"])
|
|
618
|
+
temp_mpv_year_list = []
|
|
619
|
+
temp_suv_year_list = []
|
|
620
|
+
temp_jiaoche_year_list = []
|
|
621
|
+
for item in data_json[3]["dataList"]:
|
|
622
|
+
temp_mpv_year_list.append(item[temp_df.columns[1]])
|
|
623
|
+
try:
|
|
624
|
+
temp_suv_year_list.append(item[temp_df.columns[2]])
|
|
625
|
+
temp_jiaoche_year_list.append(item[temp_df.columns[3]])
|
|
626
|
+
except: # noqa: E722
|
|
627
|
+
continue
|
|
628
|
+
temp_mpv_year_df = pd.DataFrame(temp_mpv_year_list)
|
|
629
|
+
temp_suv_year_df = pd.DataFrame(temp_suv_year_list)
|
|
630
|
+
temp_jiaoche_year_df = pd.DataFrame(temp_jiaoche_year_list)
|
|
631
|
+
big_df = pd.DataFrame(
|
|
632
|
+
[
|
|
633
|
+
temp_mpv_year_df.iloc[:, 3],
|
|
634
|
+
temp_suv_year_df.iloc[:, 3],
|
|
635
|
+
temp_jiaoche_year_df.iloc[:, 3],
|
|
636
|
+
]
|
|
637
|
+
).T
|
|
638
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2], temp_df.columns[3]]
|
|
639
|
+
big_df["月份"] = temp_df["月份"]
|
|
640
|
+
big_df = big_df[
|
|
641
|
+
["月份", temp_df.columns[1], temp_df.columns[2], temp_df.columns[3]]
|
|
642
|
+
]
|
|
643
|
+
return big_df
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
def car_market_cate_cpca(symbol: str = "轿车", indicator: str = "批发") -> pd.DataFrame:
|
|
647
|
+
"""
|
|
648
|
+
乘联会-统计数据-车型大类
|
|
649
|
+
http://data.cpcadata.com/CategoryMarket
|
|
650
|
+
:param symbol: choice of {"轿车", "MPV", "SUV", "占比"}
|
|
651
|
+
:type symbol: str
|
|
652
|
+
:param indicator: choice of {"批发", "零售"}
|
|
653
|
+
:type indicator: str
|
|
654
|
+
:return: 统计数据-车型大类
|
|
655
|
+
:rtype: pandas.DataFrame
|
|
656
|
+
"""
|
|
657
|
+
if indicator == "批发":
|
|
658
|
+
temp_df = __car_market_cate_cpca_pifa(symbol=symbol)
|
|
659
|
+
return temp_df
|
|
660
|
+
else:
|
|
661
|
+
temp_df = __car_market_cate_cpca_lingshou(symbol=symbol)
|
|
662
|
+
return temp_df
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
def car_market_country_cpca() -> pd.DataFrame:
|
|
666
|
+
"""
|
|
667
|
+
乘联会-统计数据-国别细分市场
|
|
668
|
+
http://data.cpcadata.com/CountryMarket
|
|
669
|
+
:return: 统计数据-车型大类
|
|
670
|
+
:rtype: pandas.DataFrame
|
|
671
|
+
"""
|
|
672
|
+
url = "http://data.cpcadata.com/api/chartlist"
|
|
673
|
+
params = {"charttype": "4"}
|
|
674
|
+
r = requests.get(url=url, params=params)
|
|
675
|
+
data_json = r.json()
|
|
676
|
+
temp_df = pd.DataFrame(data_json[0]["dataList"])
|
|
677
|
+
for item in temp_df.columns[1:]:
|
|
678
|
+
temp_list = []
|
|
679
|
+
for item_list in temp_df[item]:
|
|
680
|
+
temp_list.append(item_list[2])
|
|
681
|
+
temp_df[item] = pd.to_numeric(temp_list, errors="coerce")
|
|
682
|
+
return temp_df
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
def car_market_segment_cpca(symbol: str = "轿车") -> pd.DataFrame:
|
|
686
|
+
"""
|
|
687
|
+
乘联会-统计数据-级别细分市场
|
|
688
|
+
http://data.cpcadata.com/SegmentMarket
|
|
689
|
+
:param symbol: choice of {"轿车", "MPV", "SUV"}
|
|
690
|
+
:type symbol: str
|
|
691
|
+
:return: 统计数据-车型大类
|
|
692
|
+
:rtype: pandas.DataFrame
|
|
693
|
+
"""
|
|
694
|
+
url = "http://data.cpcadata.com/api/chartlist"
|
|
695
|
+
params = {"charttype": "5"}
|
|
696
|
+
r = requests.get(url=url, params=params)
|
|
697
|
+
data_json = r.json()
|
|
698
|
+
if symbol == "MPV":
|
|
699
|
+
temp_df = pd.DataFrame(data_json[0]["dataList"])
|
|
700
|
+
for item in temp_df.columns[1:]:
|
|
701
|
+
temp_list = []
|
|
702
|
+
for item_list in temp_df[item]:
|
|
703
|
+
temp_list.append(item_list[2])
|
|
704
|
+
temp_df[item] = pd.to_numeric(temp_list, errors="coerce")
|
|
705
|
+
elif symbol == "SUV":
|
|
706
|
+
temp_df = pd.DataFrame(data_json[1]["dataList"])
|
|
707
|
+
for item in temp_df.columns[1:]:
|
|
708
|
+
temp_list = []
|
|
709
|
+
for item_list in temp_df[item]:
|
|
710
|
+
temp_list.append(item_list[2])
|
|
711
|
+
temp_df[item] = pd.to_numeric(temp_list, errors="coerce")
|
|
712
|
+
else:
|
|
713
|
+
temp_df = pd.DataFrame(data_json[2]["dataList"])
|
|
714
|
+
for item in temp_df.columns[1:]:
|
|
715
|
+
temp_list = []
|
|
716
|
+
for item_list in temp_df[item]:
|
|
717
|
+
temp_list.append(item_list[2])
|
|
718
|
+
temp_df[item] = pd.to_numeric(temp_list, errors="coerce")
|
|
719
|
+
return temp_df
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
def car_market_fuel_cpca(symbol: str = "整体市场") -> pd.DataFrame:
|
|
723
|
+
"""
|
|
724
|
+
乘联会-统计数据-新能源细分市场
|
|
725
|
+
:param symbol: choice of {"整体市场", "销量占比-PHEV-BEV", "销量占比-ICE-NEV"}
|
|
726
|
+
:type symbol: str
|
|
727
|
+
https://data.cpcadata.com/FuelMarket
|
|
728
|
+
:return: 新能源细分市场
|
|
729
|
+
:rtype: pandas.DataFrame
|
|
730
|
+
"""
|
|
731
|
+
url = "http://data.cpcadata.com/api/chartlist"
|
|
732
|
+
params = {"charttype": "6"}
|
|
733
|
+
r = requests.get(url, params=params)
|
|
734
|
+
data_json = r.json()
|
|
735
|
+
if symbol == "整体市场":
|
|
736
|
+
temp_df = pd.DataFrame(data_json[0]["dataList"])
|
|
737
|
+
temp_current_year_list = []
|
|
738
|
+
temp_previous_year_list = []
|
|
739
|
+
for item in data_json[0]["dataList"]:
|
|
740
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
741
|
+
try:
|
|
742
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
743
|
+
except: # noqa: E722
|
|
744
|
+
continue
|
|
745
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
746
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
747
|
+
big_df = pd.DataFrame(
|
|
748
|
+
[temp_current_year_df.iloc[:, 2], temp_previous_year_df.iloc[:, 2]]
|
|
749
|
+
).T
|
|
750
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
751
|
+
big_df["月份"] = temp_df["month"]
|
|
752
|
+
big_df = big_df[
|
|
753
|
+
[
|
|
754
|
+
"月份",
|
|
755
|
+
temp_df.columns[2],
|
|
756
|
+
temp_df.columns[1],
|
|
757
|
+
]
|
|
758
|
+
]
|
|
759
|
+
elif symbol == "销量占比-PHEV-BEV":
|
|
760
|
+
temp_df = pd.DataFrame(data_json[1]["dataList"])
|
|
761
|
+
temp_current_year_list = []
|
|
762
|
+
temp_previous_year_list = []
|
|
763
|
+
for item in data_json[1]["dataList"]:
|
|
764
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
765
|
+
try:
|
|
766
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
767
|
+
except: # noqa: E722
|
|
768
|
+
continue
|
|
769
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
770
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
771
|
+
big_df = pd.DataFrame(
|
|
772
|
+
[temp_current_year_df.iloc[:, 2], temp_previous_year_df.iloc[:, 2]]
|
|
773
|
+
).T
|
|
774
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
775
|
+
big_df["月份"] = temp_df["月份"]
|
|
776
|
+
big_df = big_df[
|
|
777
|
+
[
|
|
778
|
+
"月份",
|
|
779
|
+
temp_df.columns[2],
|
|
780
|
+
temp_df.columns[1],
|
|
781
|
+
]
|
|
782
|
+
]
|
|
783
|
+
else:
|
|
784
|
+
temp_df = pd.DataFrame(data_json[2]["dataList"])
|
|
785
|
+
temp_current_year_list = []
|
|
786
|
+
temp_previous_year_list = []
|
|
787
|
+
for item in data_json[2]["dataList"]:
|
|
788
|
+
temp_previous_year_list.append(item[temp_df.columns[2]])
|
|
789
|
+
try:
|
|
790
|
+
temp_current_year_list.append(item[temp_df.columns[1]])
|
|
791
|
+
except: # noqa: E722
|
|
792
|
+
continue
|
|
793
|
+
temp_current_year_df = pd.DataFrame(temp_current_year_list)
|
|
794
|
+
temp_previous_year_df = pd.DataFrame(temp_previous_year_list)
|
|
795
|
+
big_df = pd.DataFrame(
|
|
796
|
+
[temp_current_year_df.iloc[:, 2], temp_previous_year_df.iloc[:, 2]]
|
|
797
|
+
).T
|
|
798
|
+
big_df.columns = [temp_df.columns[1], temp_df.columns[2]]
|
|
799
|
+
big_df["月份"] = temp_df["月份"]
|
|
800
|
+
big_df = big_df[
|
|
801
|
+
[
|
|
802
|
+
"月份",
|
|
803
|
+
temp_df.columns[2],
|
|
804
|
+
temp_df.columns[1],
|
|
805
|
+
]
|
|
806
|
+
]
|
|
807
|
+
return big_df
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
if __name__ == "__main__":
|
|
811
|
+
car_market_total_cpca_df = car_market_total_cpca(
|
|
812
|
+
symbol="狭义乘用车", indicator="产量"
|
|
813
|
+
)
|
|
814
|
+
print(car_market_total_cpca_df)
|
|
815
|
+
|
|
816
|
+
car_market_total_cpca_df = car_market_total_cpca(
|
|
817
|
+
symbol="广义乘用车", indicator="产量"
|
|
818
|
+
)
|
|
819
|
+
print(car_market_total_cpca_df)
|
|
820
|
+
|
|
821
|
+
car_market_total_cpca_df = car_market_total_cpca(
|
|
822
|
+
symbol="狭义乘用车", indicator="批发"
|
|
823
|
+
)
|
|
824
|
+
print(car_market_total_cpca_df)
|
|
825
|
+
|
|
826
|
+
car_market_total_cpca_df = car_market_total_cpca(
|
|
827
|
+
symbol="广义乘用车", indicator="批发"
|
|
828
|
+
)
|
|
829
|
+
print(car_market_total_cpca_df)
|
|
830
|
+
|
|
831
|
+
car_market_total_cpca_df = car_market_total_cpca(
|
|
832
|
+
symbol="狭义乘用车", indicator="零售"
|
|
833
|
+
)
|
|
834
|
+
print(car_market_total_cpca_df)
|
|
835
|
+
|
|
836
|
+
car_market_total_cpca_df = car_market_total_cpca(
|
|
837
|
+
symbol="广义乘用车", indicator="零售"
|
|
838
|
+
)
|
|
839
|
+
print(car_market_total_cpca_df)
|
|
840
|
+
|
|
841
|
+
car_market_total_cpca_df = car_market_total_cpca(
|
|
842
|
+
symbol="狭义乘用车", indicator="出口"
|
|
843
|
+
)
|
|
844
|
+
print(car_market_total_cpca_df)
|
|
845
|
+
|
|
846
|
+
car_market_total_cpca_df = car_market_total_cpca(
|
|
847
|
+
symbol="广义乘用车", indicator="出口"
|
|
848
|
+
)
|
|
849
|
+
print(car_market_total_cpca_df)
|
|
850
|
+
|
|
851
|
+
car_market_man_rank_cpca_df = car_market_man_rank_cpca(
|
|
852
|
+
symbol="狭义乘用车-单月", indicator="批发"
|
|
853
|
+
)
|
|
854
|
+
print(car_market_man_rank_cpca_df)
|
|
855
|
+
|
|
856
|
+
car_market_man_rank_cpca_df = car_market_man_rank_cpca(
|
|
857
|
+
symbol="狭义乘用车-累计", indicator="批发"
|
|
858
|
+
)
|
|
859
|
+
print(car_market_man_rank_cpca_df)
|
|
860
|
+
|
|
861
|
+
car_market_man_rank_cpca_df = car_market_man_rank_cpca(
|
|
862
|
+
symbol="广义乘用车-单月", indicator="批发"
|
|
863
|
+
)
|
|
864
|
+
print(car_market_man_rank_cpca_df)
|
|
865
|
+
|
|
866
|
+
car_market_man_rank_cpca_df = car_market_man_rank_cpca(
|
|
867
|
+
symbol="广义乘用车-累计", indicator="批发"
|
|
868
|
+
)
|
|
869
|
+
print(car_market_man_rank_cpca_df)
|
|
870
|
+
|
|
871
|
+
car_market_man_rank_cpca_df = car_market_man_rank_cpca(
|
|
872
|
+
symbol="狭义乘用车-单月", indicator="零售"
|
|
873
|
+
)
|
|
874
|
+
print(car_market_man_rank_cpca_df)
|
|
875
|
+
|
|
876
|
+
car_market_man_rank_cpca_df = car_market_man_rank_cpca(
|
|
877
|
+
symbol="狭义乘用车-累计", indicator="零售"
|
|
878
|
+
)
|
|
879
|
+
print(car_market_man_rank_cpca_df)
|
|
880
|
+
|
|
881
|
+
car_market_man_rank_cpca_df = car_market_man_rank_cpca(
|
|
882
|
+
symbol="广义乘用车-单月", indicator="零售"
|
|
883
|
+
)
|
|
884
|
+
print(car_market_man_rank_cpca_df)
|
|
885
|
+
|
|
886
|
+
car_market_man_rank_cpca_df = car_market_man_rank_cpca(
|
|
887
|
+
symbol="广义乘用车-累计", indicator="零售"
|
|
888
|
+
)
|
|
889
|
+
print(car_market_man_rank_cpca_df)
|
|
890
|
+
|
|
891
|
+
car_market_cate_cpca_df = car_market_cate_cpca(symbol="轿车", indicator="批发")
|
|
892
|
+
print(car_market_cate_cpca_df)
|
|
893
|
+
|
|
894
|
+
car_market_cate_cpca_df = car_market_cate_cpca(symbol="MPV", indicator="批发")
|
|
895
|
+
print(car_market_cate_cpca_df)
|
|
896
|
+
|
|
897
|
+
car_market_cate_cpca_df = car_market_cate_cpca(symbol="SUV", indicator="批发")
|
|
898
|
+
print(car_market_cate_cpca_df)
|
|
899
|
+
|
|
900
|
+
car_market_cate_cpca_df = car_market_cate_cpca(symbol="占比", indicator="批发")
|
|
901
|
+
print(car_market_cate_cpca_df)
|
|
902
|
+
|
|
903
|
+
car_market_cate_cpca_df = car_market_cate_cpca(symbol="轿车", indicator="零售")
|
|
904
|
+
print(car_market_cate_cpca_df)
|
|
905
|
+
|
|
906
|
+
car_market_cate_cpca_df = car_market_cate_cpca(symbol="MPV", indicator="零售")
|
|
907
|
+
print(car_market_cate_cpca_df)
|
|
908
|
+
|
|
909
|
+
car_market_cate_cpca_df = car_market_cate_cpca(symbol="SUV", indicator="零售")
|
|
910
|
+
print(car_market_cate_cpca_df)
|
|
911
|
+
|
|
912
|
+
car_market_cate_cpca_df = car_market_cate_cpca(symbol="占比", indicator="零售")
|
|
913
|
+
print(car_market_cate_cpca_df)
|
|
914
|
+
|
|
915
|
+
car_market_country_cpca_df = car_market_country_cpca()
|
|
916
|
+
print(car_market_country_cpca_df)
|
|
917
|
+
|
|
918
|
+
car_market_segment_cpca_df = car_market_segment_cpca(symbol="轿车")
|
|
919
|
+
print(car_market_segment_cpca_df)
|
|
920
|
+
|
|
921
|
+
car_market_segment_cpca_df = car_market_segment_cpca(symbol="MPV")
|
|
922
|
+
print(car_market_segment_cpca_df)
|
|
923
|
+
|
|
924
|
+
car_market_segment_cpca_df = car_market_segment_cpca(symbol="SUV")
|
|
925
|
+
print(car_market_segment_cpca_df)
|
|
926
|
+
|
|
927
|
+
car_market_fuel_cpca_df = car_market_fuel_cpca(symbol="整体市场")
|
|
928
|
+
print(car_market_fuel_cpca_df)
|
|
929
|
+
|
|
930
|
+
car_market_fuel_cpca_df = car_market_fuel_cpca(symbol="销量占比-PHEV-BEV")
|
|
931
|
+
print(car_market_fuel_cpca_df)
|
|
932
|
+
|
|
933
|
+
car_market_fuel_cpca_df = car_market_fuel_cpca(symbol="销量占比-ICE-NEV")
|
|
934
|
+
print(car_market_fuel_cpca_df)
|