【问题标题】:Python yahoo finance error market_cap=int(data.get_quote_yahoo(str)['marketCap']) TypeError: 'int' object is not callablePython yahoo Finance 错误 market_cap=int(data.get_quote_yahoo(str)['marketCap']) TypeError: 'int' object is not callable
【发布时间】:2020-03-01 07:13:57
【问题描述】:

我正在尝试从 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)

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

【问题讨论】:

  • 不要使用intstr 作为变量名

标签: python pandas numpy yahoo-finance pandas-datareader


【解决方案1】:

你可以这样做

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']

【讨论】:

    猜你喜欢
    • 2021-10-22
    • 1970-01-01
    • 2018-07-23
    • 2017-04-06
    • 2013-03-30
    • 2021-02-03
    • 2019-11-11
    • 2015-01-05
    • 2021-07-08
    相关资源
    最近更新 更多