pandas - 如何将该功能应用于推文数据框?
问题描述
此功能用于清理数据框 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 函数?如何 ?
解决方案
假设推文是一个系列,你可以做
tweets.apply(clean_tweets)
推荐阅读
- reactjs - React:动态地将 Img Src 传递给子组件
- docker - 如何运行 ZAP Scan 来扫描另一个容器
- dialogflow-es - Dialogflow 与团队的集成 - 提取用户信息
- azure - Azure AKS IP 地址将映像注册表列入白名单
- python - Django Rest Framework - 创建没有模型的嵌套 JSON
- ruby-on-rails - 如何找到 has_many 关联的所有者
- django - 在 Django 中自动填充两个外键字段
- google-cloud-platform - 如何将值中包含换行符的 CSV 数据导入 GCloud Big Query 表?
- asp.net-core - asp .net核心中的级联下拉列表
- javascript - 如何解密响应以将其转换为邮递员的对象?