0

I have a Pandas dataframe with some empty rows which I'd like to drop. I found some similar questions (e.g., this one and this one), but none of the solutions worked for me.

Here is what I've tried:

# Solution 1: (replace whitespace with nan and dropna()
replies_texts['text'].replace('', np.nan, inplace=True)
replies_texts.dropna(subset=['text'], inplace=True)

# Solution 2:
replies_texts = replies_texts.replace(r'^\s*$', np.nan, regex=True)

# Solution 3:
replies_texts = replies_text.replace(r'^\s+$', np.nan, regex=True)

# Solution 4:
replies_texts = replies_text.apply(lambda x: x.str.strip()).replace('', np.nan)

#Solution 5:
replies_texts = replies_text.replace(r'\s+', np.nan, regex=True).replace('',np.nan)

Here is the head of my df: enter image description here

Can someone please let me know why the above solutions don't work?

mOna
  • 2,341
  • 9
  • 36
  • 60
  • because you do not save back into the text. ie `replies_test = ....` – Onyambu Jun 09 '22 at 01:12
  • I did it but just removed it from my question to make it shorter :\ It doesn't work – mOna Jun 09 '22 at 01:15
  • 1
    You will have to provide the dataframe in text format ie `replies_texts.head(20).to_dict()` and copy and paste the result to your question – Onyambu Jun 09 '22 at 01:19

0 Answers0