Search code examples
pythongoogle-colaboratorykeyerroryfinance

Python key error for dataframe imported from yfinance


I have imported nifty50 stock data from yfinance for prediction. On running a command to print the 'Datetime' column values it throws a key error. Please help.

data load

error


Solution

  • When we reset_index() without inplace=True, it returns a new dataframe but the original dataframe remains unchanged.

    In your case dataframe 'data' index is not changed and so no column named dataframe is available.

    use data.reset_index(inplace=True)