I am new in Python.. I am trying to pull the latest prices using PX_LAST below, which works perfectly using:
from xbbg import blp, pipeline
blp.bdp(["AMZN US Equity", "SPY US Equity","KO US Equity"], ["NAME","PX_LAST"])
The issue is, I now wish to pull more prices from my csv file, which include 100 different tickers (in first column). How can I add the tickers from the df into above formula?
import pandas as pd
df = pd.read_csv(r'Desktop\tickers.csv')
print(df)
ID
0 AMZN US Equity
1 SPY US Equity
2 KO US Equity
3 WMT US Equity
4 BLK US Equity
5 GOLD US Equity
6 ...
7 ...
You need to convert your ticker column to a list and feed it as the first argument to blp.bdp:
from xbbg import blp, pipeline
import pandas as pd
df = pd.read_csv(r'Desktop\tickers.csv')
tickers = df['ID'].tolist()
blp.bdp(tickers, ["NAME","PX_LAST"])
print(df)