-2

In Python, I am attempting to have the for loop iteration result in quotations so that it passes to another function within the loop. Here is my code along with further explanation of what I'm attempting to do:

read = pd.read_csv('Stocks.csv', header=None, delimiter=',')

for x in read[0]:

    Ticker = x   #I need the x iteration to have quotations around the result to pass into the results = si.get_quote_table(x, dict_result=False) import


    results = si.get_quote_table(x, dict_result=False)  

    #The x in the parenthesis represents a stock ticker symbol from the csv file within the for loop.  This will bring back data on the stock.  It requires having quotations around the input for the si.get_quote_table to respond.

    results.to_csv('Stockdata.csv', index=False)

I would greatly appreciate any help/guidance someone can provide.

Thank you in advance!

Nick
  • 138,499
  • 22
  • 57
  • 95
Coder1044
  • 23
  • 5
  • What import are you referring to in your code? It really isn’t clear what you’re asking. – AMC Jan 18 '20 at 05:42
  • Hi Nick, the import is coming from from yahoo_fin import stock_info as si and I'm trying to access the si.get_quote_table("TICKER SYMBOL", dict_result=False) – Coder1044 Jan 18 '20 at 13:44

2 Answers2

0

you can do it like this:

x = 'BTC'

y = f"'{x}'"

print(y)

output:

'BTC'
Derek Eden
  • 4,403
  • 3
  • 18
  • 31
  • Thanks, Derek, for your suggestion. I tried it but I'm getting the following error ValueError: No tables found referencing the line: results = si.get_quote_table(Stock, dict_result=False) – Coder1044 Jan 18 '20 at 13:46
0

thank you for your contributions. I found out that the problem exists with the first row of my csv file is "Symbol" as a header and it is causing the issue. How do I go about skipping the first row or indicating that their is a header row in my code so that the iteration begins on row two? Thanks again!

Coder1044
  • 23
  • 5
  • Don’t use answers to ask new questions. Either edit the question or ask a new one. – Eric S Jan 18 '20 at 15:00
  • check the docs.. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html .. either header or skiprows – Derek Eden Jan 23 '20 at 16:52