对 python 非常陌生并且正在努力使用这个 API

问题描述

如何从 "ticker.financials"提取特定数据点。假设我想将该图表上 2020 年的营业收入分配给 "Operating_Income"

import pandas_datareader.data as web
import datetime
import requests
import yfinance as yf

ticker = yf.Ticker("MSFT")

ticker.financials

enter image description here

解决方法

你有没有试过这个:

ticker.financials.iloc[8]["Operating_Income"]

您可以查看 pandas 文档中的 iloc 属性以选择特定单元格。 https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html