Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 np
import pandas as pd

aapl = yf.download('NFLX', start="2019-01-01", end="2022-01-28")

#aapl = data.DataReader("^VIX", start='2021-1-1', end='2022-01-28', data_source='yahoo')
print(aapl.tail()) 
like image 710
M.Veloso Avatar asked Aug 31 '25 22:08

M.Veloso


2 Answers

Was trying to download a string of tickers when i ran into this problem. pip install -U yfinance pandas fixed it.

like image 52
beans89 Avatar answered Sep 05 '25 22:09

beans89


After upgrading to yfinance version 0.1.70, the problem has gone. My version of pandas is 1.4.1. use pip install -U yfinance pandas to update.

For reference, my version of yfinance was 0.1.63 and pandas was 1.4.1.

like image 25
Jim LK Yu Avatar answered Sep 05 '25 22:09

Jim LK Yu