引入rag
This commit is contained in:
+70
-22
@@ -15,34 +15,82 @@ def get_fina_info(stock_code="600699"):
|
||||
|
||||
df = stock.finance.get_core_index(stock_code=stock_code)
|
||||
|
||||
data = df[['report_date', 'report_type', 'total_rev', 'total_rev_yoy_gr','net_profit_attr_sh', 'net_profit_yoy_gr',
|
||||
'non_gaap_net_profit', 'non_gaap_net_profit_yoy_gr', 'roe_wtd', 'gross_margin', 'net_margin', 'quick_ratio',
|
||||
'inv_turn_rate', 'acct_recv_turn_rate']]
|
||||
print(df.columns)
|
||||
|
||||
last_type = data['report_type'].to_list()[0]
|
||||
last_type = df['report_type'].to_list()[0]
|
||||
|
||||
recent_df = data[data.report_type == last_type].iloc[:2,:].reset_index(drop=True)
|
||||
last_data = df[df.report_type == last_type].iloc[:2,:]
|
||||
|
||||
recent_df.rename(columns={"report_date": "报告日期",
|
||||
"report_type": "报告类型",
|
||||
"total_rev":"营业总收入",
|
||||
"total_rev_yoy_gr":"营业总收入同比增长率",
|
||||
"net_profit_attr_sh":"归母净利润",
|
||||
"net_profit_yoy_gr":"归母净利润同比增长率",
|
||||
"non_gaap_net_profit":"扣非净利润",
|
||||
"non_gaap_net_profit_yoy_gr":"扣非净利润同比增长率",
|
||||
"roe_wtd":"加权净资产收益率",
|
||||
"gross_margin":"销售毛利率",
|
||||
"net_margin":"销售净利率",
|
||||
"quick_ratio":"速动比率",
|
||||
"inv_turn_rate":"存货周转率",
|
||||
"acct_recv_turn_rate":"应收账款周转率"
|
||||
}, inplace=True)
|
||||
# 字典定义:英文指标名 -> 中文财务指标名
|
||||
column_mapping = {
|
||||
# 基础与披露信息
|
||||
'stock_code': '股票代码',
|
||||
'short_name': '股票简称',
|
||||
'report_date': '报告期',
|
||||
'report_type': '报表类型',
|
||||
'notice_date': '公告日期',
|
||||
|
||||
# 每股指标
|
||||
'basic_eps': '基本每股收益',
|
||||
'diluted_eps': '稀释每股收益',
|
||||
'non_gaap_eps': '扣非每股收益',
|
||||
'net_asset_ps': '每股净资产',
|
||||
'cap_reserve_ps': '每股公积金',
|
||||
'undist_profit_ps': '每股未分配利润',
|
||||
'oper_cf_ps': '每股经营现金流',
|
||||
|
||||
# 规模与利润指标 (元)
|
||||
'total_rev': '营业总收入',
|
||||
'gross_profit': '毛利润',
|
||||
'net_profit_attr_sh': '归母净利润',
|
||||
'non_gaap_net_profit': '扣非归母净利润',
|
||||
|
||||
# 增长率指标 (同比 YoY / 环比 QoQ)
|
||||
'total_rev_yoy_gr': '营业总收入同比增长率',
|
||||
'net_profit_yoy_gr': '归母净利润同比增长率',
|
||||
'non_gaap_net_profit_yoy_gr': '扣非归母净利润同比增长率',
|
||||
'total_rev_qoq_gr': '营业总收入环比增长率',
|
||||
'net_profit_qoq_gr': '归母净利润环比增长率',
|
||||
'non_gaap_net_profit_qoq_gr': '扣非归母净利润环比增长率',
|
||||
|
||||
# 盈利能力与收益率
|
||||
'roe_wtd': '加权净资产收益率(ROE)',
|
||||
'roe_non_gaap_wtd': '扣非加权净资产收益率(ROE)',
|
||||
'roa_wtd': '加权总资产收益率(ROA)',
|
||||
'gross_margin': '销售毛利率',
|
||||
'net_margin': '销售净利率',
|
||||
|
||||
# 现金流与收入质量比率
|
||||
'adv_receipts_to_rev': '预收款及合同负债占营收比',
|
||||
'net_cf_sales_to_rev': '销售收现率(销售现金流/营收)',
|
||||
'oper_cf_to_rev': '经营现金净流量占营收比',
|
||||
'eff_tax_rate': '实际有效税率',
|
||||
|
||||
# 偿债能力与财务杠杆
|
||||
'curr_ratio': '流动比率',
|
||||
'quick_ratio': '速动比率',
|
||||
'cash_flow_ratio': '现金流量比率',
|
||||
'asset_liab_ratio': '资产负债率',
|
||||
'equity_multiplier': '权益乘数',
|
||||
'equity_ratio': '产权比率',
|
||||
|
||||
# 运营效率与周转率/天数
|
||||
'total_asset_turn_days': '总资产周转天数',
|
||||
'inv_turn_days': '存货周转天数',
|
||||
'acct_recv_turn_days': '应收账款周转天数',
|
||||
'total_asset_turn_rate': '总资产周转率',
|
||||
'inv_turn_rate': '存货周转率',
|
||||
'acct_recv_turn_rate': '应收账款周转率'
|
||||
}
|
||||
|
||||
# 假设你的原始数据存储在 df 中,使用 rename 修改列名
|
||||
# inplace=True 表示直接在原 DataFrame 上修改
|
||||
last_data.rename(columns=column_mapping, inplace=True)
|
||||
|
||||
formatted_lines = []
|
||||
for _, row in recent_df.iterrows():
|
||||
for _, row in last_data.iterrows():
|
||||
line_items = []
|
||||
for col, val in zip(recent_df.columns, row):
|
||||
for col, val in zip(last_data.columns, row):
|
||||
# 判断是否为数字类型
|
||||
if isinstance(val, (int, float)):
|
||||
# 如果列名包含"率",则格式化为保留两位小数并加上 %
|
||||
|
||||
Reference in New Issue
Block a user