如果该类别的值计数小于 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)