0

I am working with the OULAD dataset in pandas, and i'm trying to view the labels of some specific rows. For some reason, some indices produce key errors and some do not. code:

labels = info["final_result"].copy()
print(type(labels))
print(labels)

gives the result:

<class 'pandas.core.series.Series'>
21847           Fail
19351           Fail
10841      Withdrawn
4360       Withdrawn
8991       Withdrawn
            ...     
29976    Distinction
629        Withdrawn
7329            Pass
25941           Pass
21098           Pass
Name: final_result, Length: 26074, dtype: object

and, for example

print(labels[10])

prints out:

pass

which is the correct label. However,

print(labels[9])

for whetever reason, results in:

KeyError: 9

any ideas?

plotka
  • 63
  • 1
  • 8

1 Answers1

0

probably this index is not existing in the dataframe.

Look at this exmample:

tmp = pd.DataFrame({"a":[0,1,2,3]})
tmp = tmp.drop(1)
tmp["a"][1]

KeyError: 1
kjul
  • 156
  • 6