python - 按字典值过滤 Pandas 系列
问题描述
我有一个熊猫系列words
,看起来像:
0 a
1 calculated
2 titration
3 curve
4 for
5 oxalic
6 acid
7 be
8 show
9 at
Name: word, dtype: object
我也有一个系列occurances
,看起来像:
a 278
show 179
curve 2
Name: index, dtype: object
我想过滤words
使用occurances
一个词,如果它不在occurances
或者它的值小于 100,它就会被过滤。
在给定的示例中,我想得到:
0 a
8 show
Name: word, dtype: object
isin
仅检查存在,当我尝试使用 apply\map 或[]
operator 时出现错误
系列对象是可变的,不能被散列
我也可以在 DataFrames 上使用解决方案。
解决方案
我认为您需要首先从您的occurences
系列中过滤您想要的特定单词,然后使用它的索引作为 的值.isin()
:
output = words[words.isin(occurences[occurences > 100].index)]
推荐阅读
- powershell - 在另一个 ReportServer 文件夹中创建一个 ReportServer 文件夹
- c# - 一旦消息根据意图从 LUIS 转发到 QnA,则不会从第二个实例返回到 c# 中的 LUIS。该怎么办?
- ios - Swift - 方法调配
- bash - 为数据表中的缺失值添加 0 行
- jquery - 另一个点击函数中的jQuery点击函数
- python - Flask 安装在服务器中,但仍然收到“没有名为 flask 的模块”错误
- apache-spark - 在 pyspark lambda 映射函数中使用 keras 模型
- php - Laravel 5.5 Composer 更新但弹出错误
- python - 关于Django教程官方part3 html代码的问题
- ios - IOS设备上的颤振数字键盘没有完成按钮