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?

1
  • Maybe you can apply str.strip() to the column, as shown in here Commented May 13, 2020 at 16:24

1 Answer 1

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"))]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.