0

I have a dataframe with some columns, one of this is Text that contains some text (obv).

Several cells of this columns have "no text" in there, but I have noticed ( I don't know why) that there are some spaces: for example in some rows I have "no text" in others " no text" , " no text " and " no text " and so on.

I thought to use a condition like this to remove the rows whose column Text misses it:

data = data.drop(data['no text' in data['Text']].index)

but gives me some errors (KeyError: '[False] not found in axis') I know that for stuff like this, one have to pass a boolean condition, df = df.drop(df[boolean_cond]) so what am I doing wrong?

Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
  • Maybe you can apply str.strip() to the column, as shown in [here](https://stackoverflow.com/questions/40950310/strip-trim-all-strings-of-a-dataframe) – Let's try May 13 '20 at 16:24

1 Answers1

3

Series.str.contains

If you want to remove rows which contain string as no text then you can do this:

data = data[~(data['Text'].str.contains("no text"))]
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58