r/PythonLearning • u/carticka_1 • Sep 13 '25
Key error in pandas
What is the exact problem with the given line of code throwing key error
1
u/PureWasian Sep 13 '25
1
u/PureWasian Sep 13 '25 edited Sep 13 '25
I'm only able to reproduce your exact issue and stack trace by introducing a typo on 'Alpha' or 'Juli' so my guess is you are either instantiate it with some hidden whitespace before the column name, or (less likely) you are using some inconsistent ascii characters for 'l' or 'i' in one place or the other that are very similar but not exactly a match.
2
u/carticka_1 Sep 15 '25
Gladly I found the cause for error, I just re- run the above cell that consisted the Dataframe and it finally the cell with print statement and it worked.

2
u/PolyPorcupine Sep 13 '25
You have a bracket problem, when you call data by loc , call data.loc[[indexX],[indexY1,indexY2]] enclose everything in brackets and close the X index bract.