0

I have a dataframe with a column "A" and the data type of this column is object. I want to remove all rows from the dataframe that have empty cells in the column A. What I have tried so far:

df.dropna(axis=1, subset=["A"])

di1a
  • 87
  • 1
  • 1
  • 7
  • `df[df.A.ne('')]` if empty values are strings or `df.dropna(subset=["A"])` if empty values are `NaN`s – jezrael Feb 24 '23 at 09:45
  • Both versions do not work for me – di1a Feb 24 '23 at 09:51
  • ok, so what are real empty values? Check `print (df['A'].tolist())` – jezrael Feb 24 '23 at 09:53
  • My output is [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] – di1a Feb 24 '23 at 10:13
  • 1
    `df[df.A.ne(' ')]` or ``df[df.A.str.strip().ne('')]`` should working - there is one space instead empty space. – jezrael Feb 24 '23 at 10:16
  • I thought the field had "" as empty cells, but they are filled with " " (with a space). That is why my original solution with ``df.drop(df[df.A== ""].index)`` did not work. With: ``df.drop(df[df.A== " "].index)`` it has now worked! – di1a Feb 24 '23 at 10:17
  • 1
    df[df.A.str.strip().ne('')] also worked, thank you for the hint! – di1a Feb 24 '23 at 10:19

0 Answers0