pythonpandasfor-loopquotations

How do you put quotations around a result from a for loop in Python?


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!


Solution

  • you can do it like this:

    x = 'BTC'
    
    y = f"'{x}'"
    
    print(y)
    

    output:

    'BTC'