'AttributeError: 'Index' object has no attribute 'tz_localize' [Pycharm] [Jupter]

I am new to Python. Could anyone help me with the situation below? I am running Jupter in Pycharm. Code are as below.

import yfinance as yf
import pandas as pd
amd = yf.Ticker("AMD")
amd_share_price_data = amd.history(period="max")
amd_share_price_data.head()

And there is any error, AttributeError: 'Index' object has no attribute 'tz_localize'. For detail of the error, please find below.

--------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 amd_share_price_data = amd.history(period="max")
      2 amd_share_price_data.head()

File ~/PycharmProjects/JupterProject/venv/lib/python3.10/site-packages/yfinance/base.py:279, in TickerBase.history(self, period, interval, start, end, prepost, actions, auto_adjust, back_adjust, proxy, rounding, tz, timeout, **kwargs)
    276 df["Stock Splits"].fillna(0, inplace=True)
    278 # index eod/intraday
--> 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'


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source