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.
Asked
Active
Viewed 475 times
0
-
You want to use `data.reset_index(inplace=True)`, otherwise the modification has no effect beyond the single line of code. I.e. you're getting the error, because `Datetime` is still just the name of your index. – ouroboros1 Oct 08 '22 at 15:23
-
Please [do not post images of code or errors when asking a question](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question) - see the answer in the link on why images can hinder others helping you. Also check check [How to make pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples). – MagnusO_O Oct 08 '22 at 16:33
1 Answers
0
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)

DSNS
- 26
- 2