[在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)
我非常感谢别人可以提供的任何帮助/指导。
谢谢你!
您可以这样操作:
x = 'BTC'
y = f"'{x}'"
print(y)
输出:
'BTC'
感谢您的贡献。我发现问题与我的csv文件的第一行存在“ Symbol”作为标题,这是导致问题的原因。如何跳过第一行或在代码中指出它们是标题行,以便迭代从第二行开始?再次感谢!
问题已解决。谢谢您的贡献!