首页 > 解决方案 > 按字典值过滤 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 上使用解决方案。

标签: pythonpandas

解决方案


我认为您需要首先从您的occurences系列中过滤您想要的特定单词,然后使用它的索引作为 的值.isin()

output = words[words.isin(occurences[occurences > 100].index)]

推荐阅读