-3

How do I extract a specific data point from the "ticker.financials". Say I wanted to assign operating income in 2020 on that chart to "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

furas
  • 134,197
  • 12
  • 106
  • 148
  • 1
    Please post your code as text, not a screenshot. – Barmar Apr 01 '21 at 00:19
  • always put code, data and full error message as text (not screenshot, not link) in question (not comment). – furas Apr 01 '21 at 00:20
  • it gives you `pandas dataframe` so you have to learn how to use `dataframe` – furas Apr 01 '21 at 00:21
  • Sorry about the screenshot, the problem is I don't have an error in my code I just don't know how to approach the problem at all. – Raybandz47 Apr 01 '21 at 00:22
  • you get `pandas dataframe` and you should learn `pandas`. It is powerfull module and it has many functions to work with data without `for`-loops. As for me it could be `ticker.financials.loc["Operating Income"]` but at this moment `ticker.financials` gives me only empty dataframe so I can't test it. – furas Apr 01 '21 at 00:36

1 Answers1

0

have you tried this:

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

You can look at iloc property on pandas documentation for selecting specific cells. https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.iloc.html

bhunao
  • 1
  • Thank you for the advice. What ended up working was : ticker.financials.iloc[8,0] to extract operating income from 2020-06-30 – Raybandz47 Apr 01 '21 at 00:45