filtering a dataframe with uuids returns an empty result

Question:

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?

Asked By: Jonathan

||

Answers:

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

 df.loc[df['id'] == '29c45630-7d41-11e9-8ea2-9f2bfe5760ab']
Answered By: Xrayman

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
Answered By: mozway
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.