如何在 Python 中的 for 循环结果周围加上引号?

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

在 Python 中,我试图让 for 循环迭代产生引号,以便它传递给循环内的另一个函数。这是我的代码以及对我正在尝试做的事情的进一步解释:

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)

如果有人能提供,我将不胜感激 help/guidance。

提前致谢!

你可以这样做:

x = 'BTC'

y = f"'{x}'"

print(y)

输出:

'BTC'

感谢您的贡献。我发现问题存在于我的 csv 文件的第一行 "Symbol" 作为 header 并且它导致了问题。我如何跳过第一行或在我的代码中指示它们是 header 行,以便迭代从第二行开始?再次感谢!