Pull Stock Symbols from Excel file instead of hard coding the symbols
Question:
I currently have code where I’m hard coding stock symbols in the line below.
response = c.get_quotes([‘META’,’AAPL’,’CAT’,’GOOG’])
Instead of hard coding the symbols, I want to pull them from column A in an excel file.
Column A
I’m pretty sure I would need this line below. Could someone tell me what other code I would need to have the symbols flow into the code line above to replace the hard coded symbols? Thanks
df = pd.read_excel(r’C:UsersDesktoptest.xlsm’, sheet_name=’Sheet1′)
Answers:
You can use the df
dataframe to extract the stock symbols from column A
and pass them as a list to the get_quotes
method.
import pandas as pd
df = pd.read_excel(r'C:UsersDesktoptest.xlsm', sheet_name='Sheet1')
symbols = df['A'].tolist()
response = c.get_quotes(symbols)
I currently have code where I’m hard coding stock symbols in the line below.
response = c.get_quotes([‘META’,’AAPL’,’CAT’,’GOOG’])
Instead of hard coding the symbols, I want to pull them from column A in an excel file.
Column A
I’m pretty sure I would need this line below. Could someone tell me what other code I would need to have the symbols flow into the code line above to replace the hard coded symbols? Thanks
df = pd.read_excel(r’C:UsersDesktoptest.xlsm’, sheet_name=’Sheet1′)
You can use the df
dataframe to extract the stock symbols from column A
and pass them as a list to the get_quotes
method.
import pandas as pd
df = pd.read_excel(r'C:UsersDesktoptest.xlsm', sheet_name='Sheet1')
symbols = df['A'].tolist()
response = c.get_quotes(symbols)