0

in my dataframe, I want to select the rows for which image_text is neither an empty string nor a NaN value. When I said df.dropna(subset = ['image_text'], inplace= True) I can reach NaN values so it works. Non of these 3 commands work:

  1. df[(df.image_text!='')|(df['image_text'].notna())]
  2. df[(df.image_text!='')|(math.isnan(df['image_text'])==False)]
  3. df[(df.image_text!='')|(np.isnan(df['image_text'])==False)]

I would like to add another condition after or and reach NaN values. So that I can do the whole filtering in a single command. Is there any way to do it?

Thanks :)

enter image description here

gülsemin
  • 25
  • 4
  • `df[df['image_text'].fillna('').ne('')]` or `df[df['image_text'].notna() & df['image_text'].ne('')]` – mozway Jul 07 '23 at 11:31
  • ```df[df['image_text'].notna()]``` didnt work out to reach NaN values. Also cant fill NaNs with ```df[df['image_text'].fillna('').ne('')]``` – gülsemin Jul 07 '23 at 12:29
  • Then they might not be real NaNs, maybe strings? – mozway Jul 07 '23 at 12:37
  • when I check their type, it says float but with ```df.dropna(subset = ['image_text'], inplace= True) ``` somehow i am able to filter them. – gülsemin Jul 07 '23 at 15:39
  • please provide a reproducible example of your input, without it it's unfortunately only speculations – mozway Jul 07 '23 at 15:41

0 Answers0