for symbol in stock:
try:
sector = yf.Ticker(symbol).info['sector']
name = yf.Ticker(symbol).info['shortName']
cap = yf.Ticker(symbol).info['marketCap']
except:
sector = 'None'
name = 'None'
information[symbol,name,sector,cap] = web.get_data_yahoo(symbol, s,e)['Adj Close']
idx = pd.MultiIndex.from_tuples(information.columns)
information.columns = idx
错误如下
[*********************100%***********************] 1 of 1 completed
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-26-844c416a2200> in <module>
7 sector = 'None'
8 name = 'None'
----> 9 information[symbol,name,sector,cap] = web.get_data_yahoo(symbol, s,e)['Adj Close']
10 idx = pd.MultiIndex.from_tuples(information.columns)
11 information.columns = idx
NameError: name 'cap' is not defined
1)我成功地将调整后的价格,部门和简称输入到数据框中并导出到excel文件,但是当我获得市值时,错误就来了,有人可以帮忙吗?谢谢!
其中“股票”包含大量的行情自动收录器
filename=r'C:\Users\User\Desktop\from_python\data_from_python2.xlsx'
yeah = pd.read_excel(filename, sheet_name='entry')
stock = []
stock = list(yeah['name'])
stock = [ s.replace('\xa0', '') for s in stock if not pd.isna(s) ]
adj_close=pd.DataFrame([])
high_price=pd.DataFrame([])
low_price=pd.DataFrame([])
volume=pd.DataFrame([])
information=pd.DataFrame([])
我还可以将以下信息放入数据框以取得卓越效果吗?它与字符和数字的结果数据有所不同,导致不同的python语言导致上述错误吗?
[“语言”,“区域”,“ quoteType”,“可触发”,“ quoteSourceName”, 'currency','preMarketChange','preMarketChangePercent', 'preMarketTime','preMarketPrice','regularMarketChange', 'regularMarketChangePercent','regularMarketTime','regularMarketPrice', 'regularMarketDayHigh','regularMarketDayRange','regularMarketDayLow', 'regularMarketVolume','regularMarketPreviousClose','bid','ask', 'bidSize','askSize','fullExchangeName','financialCurrency', 'regularMarketOpen','averageDailyVolume3Month', 'averageDailyVolume10Day','fiftyTwoWeekLowChange', 'fiftyTwoWeekLowChangePercent','fiftyTwoWeekRange', 'fiftyTwoWeekHighChange','fiftyTwoWeekHighChangePercent', 'fiftyTwoWeekLow','fiftyTwoWeekHigh','dividendDate', 'earningsTimestamp','earningsTimestampStart','earningsTimestampEnd', 'trailingAnnualDividendRate','trailingPE', 'trailingAnnualDividendYield','marketState','epsTrailingTwelveMonths', 'epsForward','sharesOutstanding','bookValue','fiftyDayAverage', 'fiftyDayAverageChange','fiftyDayAverageChangePercent', “ twoHundredDayAverage”,“ twoHundredDayAverageChange”, 'twoHundredDayAverageChangePercent','marketCap','forwardPE', 'priceToBook','sourceInterval','exchangeDataDelayedBy','tradeable', 'firstTradeDateMilliseconds','priceHint','exchange','shortName', 'longName','messageBoardId','exchangeTimezoneName', 'exchangeTimezoneShortName','gmtOffSetMilliseconds','market', 'esgPopulated','price']