python - 如果熊猫列中只有单词,如何在熊猫数据框中删除一行
问题描述
如果列中只有一个单词,我们如何在 pandas 数据框中删除一整行
例子:
'the cat likes mice',
'the dog likes the cat',
'dog'
返回
'the cat likes mice',
'the dog likes the cat'
解决方案
如何使用该pd.Series.str.contains
方法查找空格:
df = pd.DataFrame({'items': ['the cat likes mice',
'the dog likes the cat',
'dog']})
df = df[df['items'].str.contains(' ')]
推荐阅读
- progressive-web-apps - PWA 清单 json 设置为显示:全屏 - 它适用于 Android 设备,但不适用于 Windows 桌面
- javascript - 当我使用 .map 获取 API 返回时,我得到的响应是有效载荷,如何从映射调用中获取真实数据?
- vba - 范围适用于公式,但不适用于自定义函数
- authentication - 如何在java应用程序中获取okta登录页面
- ios - macOS - pf.conf - 根据用户从一个接口路由到另一个接口
- python - 找不到表时如何优雅地处理pandas read_html?
- ms-access - 访问 365 和 accdr 文件
- javascript - 在 JavaScript 中将值转换为 0-99 和 0-100 的最佳方法?
- php - 在 WooCommerce 管理员订单列表上显示产品图片的问题
- node.js - 在验证和序列化中检索数据。fastify 的问题