I was reading the book - "Python for Data Analysis" and doing code side-by-side on Jupiter notebook. Here is my DataFrame named data :
one three four
Ohio 0 2 3
Colorado 4 6 7
Utah 8 10 11
New York 12 14 15
and I used : data.loc[:"one"]
.
It gives a Keyerror 'one'.
But when I use: data.loc[:"Utah" , "one"]
. It doesn't give any error.
Can anyone tell me what's going one here.
So the problem is solved.
The error was I was missing a comma(,).
I have to do something like this :
data.loc[:,"one"]
but i was doing data.loc[:"one"]
which gave error. But we don't have to include "," while we are dealing with more than one column or it will give error( kind of weird syntax ).
eg : do this : data.loc[:"Utah","one"]
not this : data.loc[:,"Utah","one"]