小编MD *_*HAN的帖子

如何解决'列标签'Avg_Threat_Score'不唯一。'?熊猫问题

运行代码时,我面临以下错误。错误 - 列标签“Avg_Threat_Score”不是唯一的。

我正在创建一个数据透视表并希望将值从高到低排序。

pt = df.pivot_table(index = 'User Name',values = ['Threat Score', 'Score'], 
        aggfunc = {
                   'Threat Score': np.mean,
                   'Score' :[np.mean, lambda x: len(x.dropna())]
                  }, 
        margins = False) 

new_col =['User Name Count', 'AVG_TH_Score', 'Avg_Threat_Score']
pt.columns = [new_col]
#befor this code is working, after that now working 
df = df.reindex(pt.sort_values
                    (by = 'Avg_Threat_Score',ascending=False).index)
Run Code Online (Sandbox Code Playgroud)

需要对列“Avg_Threat_Score”的值进行高低排序

python pivot pivot-table pandas

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

标签 统计

pandas ×1

pivot ×1

pivot-table ×1

python ×1