【问题标题】:Pull Stock Symbols from Excel file instead of hard coding the symbols从 Excel 文件中提取股票符号而不是对符号进行硬编码
【发布时间】:2023-02-11 11:06:20
【问题描述】:

我目前有代码,我在下面的行中对股票代码进行硬编码。

response = c.get_quotes(['META','AAPL','CAT','GOOG'])

我不想对符号进行硬编码,而是想将它们从 excel 文件的 A 列中提取出来。

A列

我很确定我需要下面这一行。有人能告诉我还需要哪些其他代码让符号流入上面的代码行以替换硬编码符号吗?谢谢

df = pd.read_excel(r'C:\Users\Desktop\test.xlsm', sheet_name='Sheet1')

【问题讨论】:

    标签: python excel


    【解决方案1】:

    您可以使用 df 数据框从 A 列中提取股票代码,并将它们作为列表传递给 get_quotes 方法。

    import pandas as pd
    
    df = pd.read_excel(r'C:UsersDesktop	est.xlsm', sheet_name='Sheet1')
    symbols = df['A'].tolist()
    
    response = c.get_quotes(symbols)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多