Questions tagged [yfinance]

For issues dealing with the Yahoo! Finance market data downloader. yfinance aims to solve this problem by offering a reliable, threaded, and Pythonic way to download historical market data from Yahoo! finance.

Documentation

How to install

# With Conda at the Anaconda prompt
conda install -c ranaroussi yfinance

# With pip
pip install yfinance --upgrade --no-cache-dir

Answers

  • How to deal with multi-level column names downloaded with yfinance
    • yfinance returns a pandas.DataFrame with multi-level column names, where there is a level for the ticker names and a level for the ticker prices.
    • This answer deals with the following issue:
      • How to correctly read the the multi-level columns after saving the dataframe to a csv with pandas.DataFrame.to_csv
      • How to download single or multiple tickers into a single dataframe with single level column names and a ticker column
  • Pandas column multi-index to rows
    • Shows how to download multiple ticker symbols and flatten the multi-level column names into single level columns with the ticker as one column.
565 questions
3
votes
2 answers

yFinance - Obtain all symbols

Is there a way to grab all symbols available through yFinance (not yahoo finance)? Here's the package I'm referring to by ranaroussi: https://pypi.org/project/yfinance/ I've scanned the blog and blog comments, GitHub, some tutorials, and found no…
ajpri
  • 31
  • 3
3
votes
2 answers

yfinance: Don't see time on day when choosing one hour intervals

I use the Python package yfinance to get the historical stock prices of a stock (in this example, Tesla's stock). When I do the following, and fetch the stock price for the last week as one minute intervals: import yfinance as…
HelloGoodbye
  • 3,624
  • 8
  • 42
  • 57
3
votes
2 answers

Dividend rates and dates for multiple stocks at once using python

I am trying to download multiple stocks dividend amounts and respective dates using yfianance package and trying to save it in a python Data Frame. I am using following code import yfinance as yf data = pd.DataFrame() stock_list =…
3
votes
3 answers

AttributeError: module 'yfinance' has no attribute 'download'

I'm trying to import yfinance and some stocks into pandas dataframe. Initially had major issues importing yfinance. I installed using pip but still had to manually put in the files to actually get rid of the no module error. This is my code so…
HJ10
  • 35
  • 1
  • 5
3
votes
2 answers

Timestamp not showing up in yfinance package in Python

I am trying to pull stock price history at 1 hour intervals through the Yahoo Finance API using the yfinance package. I run the following code. import yfinance as yf msft = yf.Ticker("MSFT") df = msft.history(period = "5d", interval =…
abhigdeal
  • 162
  • 3
  • 9
3
votes
6 answers

How can I using yfinance to get fundamental ratios ( such as P/E, P/B )

I've been wondering how can I get a series fundamentals such as P/E ratio of a company using yfinance. historical ratios for multiple company . I have tried import yfinance as yf rio=yf.Ticker("RIO.AX") rio.financials but my result give me the…
Andy
  • 83
  • 1
  • 1
  • 5
3
votes
3 answers

yf.Tickers from yfinance to download information for multiple tickers and dynamically access each of them

My question is how to dynamically access each ticker when using yf.Tickers from yfinance in Python? For example, I have a list of tickers: ['AAPL', 'MSFT', 'AMD'] and use the following code to download thru yfinance: import yfinance as yf tickers =…
DLW
  • 121
  • 1
  • 2
  • 8
2
votes
1 answer

i have an error in my python code key error ['logo_url'] not in index

def update_data(n, val): # inpur parameter(s) if n == None: return "Hey there! Please enter a legitimate stock code to get details.", "https://melmagazine.com/wp-content/uploads/2019/07/Screen-Shot-2019-07-31-at-5.47.12-PM.png",…
2
votes
1 answer

Invalid synthax in df while fetching ESG data from Yahoo Finance

Updated post for csv file structure. csv file has the following structure: Symbol AAL AAON AAPL ABCB Tickers does not have quotation marks. I have a problem with my code in Python. I am trying to download historical ESG data from Yahoo Finance…
jrpars1
  • 35
  • 4
2
votes
2 answers

How to plot timeseries data in VSCode using pandas

here's some code that I'm using to try to plot a timeseries of BP share data from yfinance in a Jupyter notebook in VSCode. import pandas as pd import matplotlib.pyplot as plt %matplotlib inline import seaborn as sns # Import yfinance…
elksie5000
  • 7,084
  • 12
  • 57
  • 87
2
votes
0 answers

In Python is there a way using yfinance library to download 10y history of Balance Sheet, Income Statement, Cash flow?

Using Python and the yfinance library, is there a way to download a long period of quarterly or yearly financial statements (I'd prefer quarterly) like 10 years? I am interested in Balance Sheet, Income statement, and cash flow. The common script…
2
votes
1 answer

Retrieve a lot of data from Yahoo finance

I have a csv file which contains the ticker symbols for all the stocks listed on Nasdaq. Here is a link to that csv file. One can download it from there. There are more than 8000 stocks listed. Following is the code import pandas as pd import…
Shawn Brar
  • 1,346
  • 3
  • 17
2
votes
1 answer

Yfinance doesen't download the full price histoy

I'm running the exact same code on two different computers. I'm using Yfinance to download stock/index price history. The target is to download the whole history available in Yahoo finance. The code which I use follows, where I use the option Max.…
LucaG
  • 341
  • 3
  • 11
2
votes
1 answer

How to iterate over YFinance data

I'm trying to get some data for a single stock and save this data on database. I'm using YFinance, which gets data from Yahoo Finance. ticker = yf.Ticker("BBAS3.SA") data = ticker.history(period="1y") print(data[['High', 'Low', 'Open',…
starbolt
  • 437
  • 1
  • 3
  • 15
2
votes
3 answers

AttributeError: 'Index' object has no attribute 'tz_localize' with yfinance

'this error occurs only with some stocks, for instance with NFLX, KO or MCD, but not with AAPL or INFy both with yfinance 0.1.63 and 0.1.69, pandas 1.2.3 or 1.4' import yfinance as yf from pandas_datareader import data import os import numpy as…
M.Veloso
  • 41
  • 1
  • 2
1 2
3
37 38