首页 > 解决方案 > 如何将该功能应用于推文数据框?

问题描述

此功能用于清理数据框 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

数据框仅包含一列(推文)

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

- 我需要在推文(数据框中的行)上应用 clean_tweets 函数?如何 ?

标签: pandasdataframearabicdata-cleaningtweets

解决方案


假设推文是一个系列,你可以做

tweets.apply(clean_tweets)

推荐阅读