0

This function is for cleaning arabic tweets in dataframe pandas

def clean_tweets(s):
    s= s.replace("RT",'')
    r = re.compile(r"(?:^|\s)([@#h])(\w+)")
    s=re.sub(r,"",s)
    s = re.sub('[:/.…!"()]', '', s)
    s = re.sub('[a-zA-Z]', '', s)
    s = re.sub('[0-9]', '', s)
    return s

Dataframe contains just one column (Tweets)

Tweets
0 الجنائية" ترفض *- طلب...
1 كورونا" في  @@@#$البيت...
2 طيران الإمارات تت...
3 خلال 24 ساعة.. #### أمري...
4 &&تنقب عن النفط...```

- I need to apply clean_tweets function on tweets (rows in dataframe) ? how ?

mohdsh334
  • 21
  • 5

1 Answers1

1

Assuming tweets is a Series, you can do

tweets.apply(clean_tweets)