我正在尝试对 DataFrame 的列 score 进行等分。
我使用以下代码:
np.percentile(df['score'], np.arange(0, 100, 10))
我的问题是分数,有很多零。如何过滤掉这些 0 值并只对其余值进行十分位数处理?
请您参考如下方法:
使用 bool 索引过滤它们:
df.loc[df['score']!=0, 'score']
或
df['score'][lambda x: x!=0]
并将其传递给百分位数函数。
np.percentile(df['score'][lambda x: x!=0], np.arange(0,100,10))
