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

使用pdblp拉取CUSIP对应彭博数据并转换为目标DataFrame格式

实现方案

你想要的宽格式输出可以通过pdblp原生参数直接实现,不需要额外手动转换表结构:

import pdblp

# 初始化连接
con = pdblp.BCon(debug=False, port=8194, timeout=5000)
con.start()

# 替换为你的CUSIP列表和待查询字段
cusip_list = ["/cusip/xxxxxxxxx", "/cusip/yyyyyyyyy"]
feature_list = ["Feature1", "Feature2", "Feature3"]

# 传入long_fmt=False直接得到宽格式结果,Feature为列,CUSIP为索引
df = con.ref(cusip_list, feature_list, long_fmt=False)

# 如果需要把CUSIP转为单独列,执行以下代码
df = df.reset_index(names="cusip")

如果你使用的是旧版本pdblp,没有long_fmt参数,再通过pivot手动转换即可:

# 先查询得到长格式原始数据
df_long = con.ref(cusip_list, feature_list)
# 转换为宽格式
df_wide = df_long.pivot(
    index="ticker", 
    columns="field", 
    values="value"
).reset_index(names="cusip")

注意事项

彭博接口对单次请求的标的数量有限制,5000个CUSIP建议拆分为2-3个批次分别请求,再拼接结果,避免触发限流导致请求失败。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 19:48:01