Home > Software engineering >  Pandas DataFrame indexing problem from 40,000 to 49,999
Pandas DataFrame indexing problem from 40,000 to 49,999

Time:11-09

I have a strange problem with my code (At least it is strange for me!).

I have a Pandas DataFrame called "A". One of the column names is "asin". I want to execute all specific rows including my data. So I write this simple code:

df2 = A[A['asin']=='B0000UYZG0']

And it works normally as expected, except for data from 40,000 to 499,999!! It doesn't work on these data series at all!

Refer to the picture, df2 = A[A['asin']=='0077614992'] (related to 50,000) works but df2 = A[A['asin']=='B0006O0WW6'] (related to 49,999) does not work!

Pic1

I do not have tried all 10,000 data! But randomly I test them and have no answer.

CodePudding user response:

I have grow accustomed to fixing bugs such as this one, usually when that happen is because of an alternative dtype or maybe because the string you see displayed to you isn't actually THE string itself. It seen your issue is mostly on the second part. So lets first clear your "string" column from any white spaces.

df2['asin'] = df2.asin.str.strip() 
# I am going with the idea that that is your non functional df object

After that try rerunning your filter

df2[df2['asin'].eq('0077614992')]
  • Related