Reputation: 39
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. E.g:
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.
Upvotes: 0
Views: 415
Reputation: 34086
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.
Upvotes: 3