Python雅虎财务错误market_cap = int(data.get_quote_yahoo(str)['marketCap'])TypeError:'int'对象不可调用

我正在尝试从yfinance(可用于repl.it)获取有关各种公司市值的数据,但是在第一次停止运行后

import yfinance as yf
import numpy as np
from pandas_datareader import data

Tickers=["AAPL","GOOG","RY","HPQ"]
UndervaluedCompanies=[]

for str in Tickers:
  tickers = [(str)]
  print(tickers)

  market_cap=int(data.get_quote_yahoo(str)['marketCap'])

  stock= yf.Ticker(str)
  earnings=(stock.earnings)

  List=([earnings[i].tolist() for i in earnings.columns])
  profit=(List[1])

  for int in profit:
    ratio=(market_cap/int)
    print(ratio)

我想去查找列表中所有股票的市盈率,但没有得到市值数据

gezhaohe123 回答:Python雅虎财务错误market_cap = int(data.get_quote_yahoo(str)['marketCap'])TypeError:'int'对象不可调用

您可以做到

import pandas_datareader as web

tickers=["AAPL","GOOG","RY","HPQ"]

# Get market cap (not really necessary for you)
market_cap_data = web.get_quote_yahoo(tickers)['marketCap']

# Get the P/E ratio directly
pe_data = web.get_quote_yahoo(tickers)['trailingPE']

# print stock and p/e ratio
for stock,pe in zip(tickers,pe_data):
    print(stock,pe)

# More keys that can be used
      ['language','region','quoteType','triggerable','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']
本文链接:https://www.f2er.com/3163165.html

大家都在问