简体   繁体   中英

Empty dataframe when filtering

I have a dataframe that looks like this:

在此处输入图像描述

Now I'd like to filter like this:

df1.loc[df1['PZAE'] == 'HAE']

However, I am getting an empty dataframe. 在此处输入图像描述

What am I doing wrong here?

Try df1.loc[df1['PZAE']=="'HAE'"]

Details:

the column 'PZAE' contains str starting and finishing by ' that's why you have to include them in the condition

@Pi-R's answer is probably what you are looking for, but in case it is useful, you can also match partial strings like so:

df1.loc[df1['PZAE'].str.contains('HAE')]

That should also give you what you want here.

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