运行代码时,我面临以下错误。错误 - 列标签“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”的值进行高低排序