Yahoo Financials错误:“ NoneType”对象不可下标

时间:2020-04-29 13:34:23

标签: python pandas yahoo-finance

我正在尝试从CSV中加载符号列表,然后从YahooFinancials中提取历史股票信息。该程序一直运行到我得到的最后一个组件:'NoneType' object is not subscriptable
我非常感谢您的帮助。这是我的第一篇文章,因此,如果需要更多信息,请告诉我。

这是我的代码:

import pandas as pd
import yfinance as yf
from yahoofinancials import YahooFinancials
import datetime

#import csv list of symbols
stocksmini = pd.read_csv('watchlistmini.csv')
stocksmini
symbollist = stocksmini['Symbol'].tolist()
symbollist

#symbollist has this format:
['BASWW', 'BBLC', 'EMGE', 'VBVT']

#pull stock info
test = symbollist

yahoo_financials = YahooFinancials(test)

data = yahoo_financials.get_historical_price_data (start_date='2020-01-01',
                                                   end_date='2020-04-26',
                                                   time_interval='daily')

test2 = pd.DataFrame({
    a: {x['formatted_date']: x['adjclose'] for x in data[a]['prices']} for a in test
})

test2

这是我得到的错误:

Error (Note: error referencing line starting with a: {x...)
TypeError: 'NoneType' object is not subscriptable

0 个答案:

没有答案