财务大数据分析李轶伦(1)

更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
python # 1. 导入 Python 库文件 import requests import ______ import pandas as pd import ______ # 2. 输入采集的信息:建设银行,2024年-2026年利润表和现金流量表。 code = [("______","建设银行")] year = ["______","______","______"] report_period_id = ["5000"] url = ["https://ssecurity.seentao.com/debug/security/security.______.get", "https://ssecurity.seentao.com/debug/security/security.______.get"] name_dict = {"incomestatement": "利润表", "cashflow": "现金流量表", "balancesheet": "资产负债表"} try: # 3. 利用 for 循环,采集数据 for one in url: name = re.search('Vsecurity\\.(.*)\\.get', one).group(1) sheet_name = 'sz_' + name data = pd.DataFrame() for S_id in code: stock_id = S_id[0] for b in report_period_id: postdata = {"stockId": stock_id, "reporttype": b, "callType": "collection"} json_data = requests.post(one, postdata).json()['result'] df = pd.DataFrame(json_data) df = df[df['reportyear'].isin(year)] data = pd.concat([data,df]) except Exception as e: print(e) continue name_file = pd.read_excel('数据采集/中英文对照表/中英指标对照.xlsx', sheet_name=sheet_name) name_dir = dict(zip(name_file['en'], name_file['ch'])) data.rename(columns=name_dir, inplace=True) print(data) end_data = data[name_file['ch']] end_data.to_excel(f"数据采集 / 任务 6/{'&'.join([i[1] for i in code])}_{name_dict.get(name)}采集结果{int(time.time())}.xlsx", encoding='utf-8', index=False) except Exception as e: print('采集失败', e)