Home > OS >  filtering a dataframe with uuids returns an empty result
filtering a dataframe with uuids returns an empty result

Time:01-21

I have this data frame:

df:

id hint
29c45630-7d41-11e9-8ea2-9f2bfe5760ab None
61afc910-3918-11ea-b078-93fcef773138 Yes

and I want to find the first row that has this id = 29c45630-7d41-11e9-8ea2-9f2bfe5760ab

when I run this code:

df[df['id'] == '29c45630-7d41-11e9-8ea2-9f2bfe5760ab']

return empty!!! and the type of this id is "object"

but I really have this id!!

how can I find it?

CodePudding user response:

You code didn't work because you have UUIDs, not strings, you first need to convert to string:

df[df['id'].astype(str).eq('29c45630-7d41-11e9-8ea2-9f2bfe5760ab')]

Output:

                                     id  hint
0  29c45630-7d41-11e9-8ea2-9f2bfe5760ab  None

CodePudding user response:

You have to use property DataFrame.loc[source], read here

 df.loc[df['id'] == '29c45630-7d41-11e9-8ea2-9f2bfe5760ab']
  • Related