You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Excel A列提取股票代码替换硬编码值用于接口调用

从Excel提取股票代码传入接口的实现方法

补充代码步骤

  • 先从读取好的DataFrame中提取A列数据,转换为接口需要的列表格式:
    # 提取A列(索引为0的列),过滤空值后转成列表
    stock_codes = df.iloc[:, 0].dropna().tolist()
    
    如果A列有明确的表头(比如"Stock Code"或"股票代码"),也可以直接用列名选取,可读性更强:
    stock_codes = df['股票代码'].dropna().tolist()
    
  • 把硬编码的列表替换成提取到的stock_codes,调用接口:
    response = c.get_quotes(stock_codes)
    

完整代码示例

import pandas as pd

# 读取指定Excel文件和工作表
df = pd.read_excel(r'C:\Users\Desktop\test.xlsm', sheet_name='Sheet1')
# 提取A列的股票代码,处理空值并转为列表
stock_codes = df.iloc[:, 0].dropna().tolist()
# 传入接口调用
response = c.get_quotes(stock_codes)

注意事项

  • 使用dropna()过滤空值很关键,避免将无效的空条目传入接口导致报错
  • 确保Excel的A列中只有有效的股票代码,没有无关内容

内容的提问来源于stack exchange,提问作者user3444610

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.01 11:11:07