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

enter image description here

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′)

Asked By: user3444610

||

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)
Answered By: AboAmmar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.