简体   繁体   中英

filtering a dataframe with uuids returns an empty result

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?

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

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

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

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