-1

I have the following dataframe:

index        text        is_retweet
0            Test        False
1            RT bar      False
2            RT bazz     False
3            Test2       False

I want to delete the rows that begin with "RT"

I tried this:

my_df.drop(my_df.index[my_df['text'].find("RT") == 0], inplace = True)

But I get this error:

AttributeError: 'Series' object has no attribute 'find'
0

2 Answers 2

1

Use pandas.Series.str.startswith:

new_df = df[~df["text"].str.startswith("RT")]
print(new_df)

Output:

   index   text  is_retweet
0      0   Test       False
3      3  Test2       False
Sign up to request clarification or add additional context in comments.

Comments

1

Another option taking the position of characters:

df1 = df[df['text'].str[0:2] != 'RT']
df1

ouput:

    index   text    is_retweet
0       0   Test    False
3       3   Test2   False

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.