python - 从数据框列中删除类似空格+字母+空格的字符串
问题描述
我在数据框中有这些句子列:
"I love x cat"
"You x x"
"x x x x"
"This example is better"
我想用 python 删除“x”
"I love cat"
"You"
""
"This example is better"
但我不知道我怎么能得到它,因为单词 example 有“x”,我不想删除它
谢谢!
解决方案
如果你有一个数据框,那么你可以使用:
df['your col name here'] = df['your col name here'].apply(lambda s: ' '.join(i for i in s.split(' ') if i != 'x'))
推荐阅读
- mobile - Google-oauth 回调适用于桌面浏览器,但不适用于移动浏览器
- vb.net - Vb.net 错误“'InvalidArgument='0' 的值对'index' 无效。参数名称:index'”
- python - 字典和列表的排序问题
- java - 有没有办法将自定义对象列表放在 cloud-firestore 中的自定义对象中
- javascript - 如何通过 Javascript 操作 HTML 自定义验证的外观?
- video - 如何拆分具有奇怪关键帧“pkt_pts_time=N/A”的视频?
- javascript - 与 Web Worker 通信时保留对象身份
- makefile - make build 后 makefile 不重建
- kubernetes - 作为一个集群的一部分,您可以在多个云上运行 Kubernetes 节点吗?
- firebase - 如何迁移非常旧的 Android 应用 GCM->FCM,其中应用既是发送者又是接收者