yfinance icon indicating copy to clipboard operation
yfinance copied to clipboard

in .history(period = 'max') funtion I got this error: AttributeError: 'Index' object has no attribute 'tz_localize'

Open 1uislopez opened this issue 2 years ago • 2 comments

Hi,

how can I fix the below error?

Code:

google = yf.Ticker("GOOG") google_data = google.history(period="max")

Error:

--> 279 df.index = df.index.tz_localize("UTC").tz_convert( 280 data["chart"]["result"][0]["meta"]["exchangeTimezoneName"]) 282 if params["interval"][-1] == "m": 283 df.index.name = "Datetime"

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

Thanks in advice

1uislopez avatar Jan 24 '23 15:01 1uislopez

Hi, you need to add a line of code to modify the DataFrame index to timezone-insensitive

google = yf.Ticker("GOOG") google_data = google.history(period="max") google_data.index = google_data.index.tz_localize(None) # Remove timezone

PatrickDionne avatar Jan 28 '23 15:01 PatrickDionne

@PatrickDionne That won't fix errors originating inside yfinance

@1uislopez What version are you using? I can't find that code. But I've seen error before and potential fix is in branch fix/prices-index-not-datetime for you to test (instructions #1080)

ValueRaider avatar Jan 28 '23 16:01 ValueRaider