简体   繁体   中英

Pandas not finding all values in column

When I try looking for all rows with a specific value in a column I don't get all the rows like when I filter for it in excel. Eg:

Column 1 is of type object and has rows of different numbers mixed with chars sometimes.

df[df['column1']== 250] returns 100 results

df[df['column1']=='250'] returns 50 results

What is causing this and how can I fix it?

I tried converting it again to object but no success.

Looks like some values in column1 are str and some are int .

Convert all values in one type, like this using Series.astype :

df['column1'] = df['column1'].astype(str)

then do this:

df[df['column1']== '250'] 

You should get 150 records back now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM