Pandas 如何将该函数应用于tweets数据帧?
此功能用于清除数据帧中的阿拉伯语tweetPandas 如何将该函数应用于tweets数据帧?,pandas,dataframe,arabic,data-cleaning,tweets,Pandas,Dataframe,Arabic,Data Cleaning,Tweets,此功能用于清除数据帧中的阿拉伯语tweet 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 T
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 &&تنقب عن النفط...```
数据帧只包含一列(Tweets)
-我需要在tweets(数据帧中的行)上应用clean_tweets功能吗?
怎么做?假设推特是一个系列,你可以这样做
tweets.apply(clean_tweets)
df['cleaned']=df['Tweets']。应用(clean_Tweets)
这是否回答了您的问题?