I have a Pandas DataFrame
with NAME
index and one of the columns called CLASS
:
df =
CLASS
NAME
John Math
John Science
Lisa Music
Now if I extract df.loc['John', 'CLASS']
, it returns a Series
, but if I extract df.loc['Lisa', 'CLASS']
it returns a str
.
Is there a way for me to force the returned value to be Series
(i.e. ['Music', ]
)? I need to iterate through that returned object right afterwards and I don't want to go through Math
, Science
in John's case (desired) but M, u, s, i, c
in Lisa's case (not desired).