mercredi 13 juillet 2016

Cannot get right slice bound for non-unique label when indexing data frame with python-pandas


I have such a data frame df:

a         b
10        2
3         1
0         0
0         4
....
# about 50,000+ rows

I wish to choose the df[:5, 'a']. But When I call df.loc[:5, 'a'], I got an error: KeyError: 'Cannot get right slice bound for non-unique label: 5. When I call df.loc[5], the result contains 250 rows while there is just one when I use df.iloc[5]. Why does this thing happen and how can I index it properly? Thank you in advance!


Aucun commentaire:

Enregistrer un commentaire