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

Viewed 1338

'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()) 
3 Answers

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

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.

From what I saw on the Github for YFinance, this is already an issue with the new version of Pandas (source: here). Try installing an older version of pandas with pip install pandas==1.3.5 and see if that helps.

Related