小编Kar*_*tam的帖子

如果该类别的 value_count 小于 10,则用常量替换列值 python

如果该类别的值计数小于 10,我想用“其他”替换熊猫数据框中的所有类别。

我正在尝试这样的事情。

df['variable'].where(df['variable'].apply(lambda x: x.map(x.value_counts()))<=10, "other")
Run Code Online (Sandbox Code Playgroud)

但我收到以下错误:

AttributeError: 'str' object has no attribute 'map'
Run Code Online (Sandbox Code Playgroud)

python pandas

5
推荐指数
1
解决办法
1385
查看次数

标签 统计

pandas ×1

python ×1