Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

财务数据没有trade_date字段 #1

Open
ylliu opened this issue Mar 17, 2025 · 1 comment
Open

财务数据没有trade_date字段 #1

ylliu opened this issue Mar 17, 2025 · 1 comment

Comments

@ylliu
Copy link

ylliu commented Mar 17, 2025

Image
你看看这个地方怎么处理呀

分批获取财务数据

def load_financial_data(start_date='20230101', end_date='20240306', batch_size=50):
"""
分批获取财务数据,每批最多获取batch_size只股票,每批之间延时5秒,防止Tushare限流
"""
stock_list = get_stock_list_with_retry()

all_data = []
for i in range(0, len(stock_list), batch_size):
    batch = stock_list[i:i+batch_size]
    print(f"正在获取第 {i//batch_size + 1} 批财务数据,共 {len(batch)} 只股票...")
    for ts_code in batch:
        try:
            df = pro.fina_indicator(ts_code=ts_code, start_date=start_date, end_date=end_date)
            all_data.append(df)
        except Exception as e:
            print(f"获取 {ts_code} 财务数据失败,跳过。错误信息:{e}")
    time.sleep(5)  # 每批次间隔5秒,降低触发限流风险
print(all_data[0:5])
financial_data = pd.concat(all_data, ignore_index=True)
financial_data['trade_date'] = pd.to_datetime(financial_data['trade_date'])   #这里
@ylliu
Copy link
Author

ylliu commented Mar 17, 2025

财务数据转换那一块的代码也提供下吧 pe_ttm那些计算的代码 现在应该跑不起来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant