小编use*_*405的帖子

Python使用其他列值创建具有最高值(%)的新列

我无法找到自动获得最高n%的函数,因此我将最大值和最小值以及计算出的数字排序为前25%和最小25%范围.我想要做的是在新栏目中创建一个标志,说让我们说这个客户的收入排在前25%.

from heapq import nsmallest
top_max = avg_cust_data.nlargest(10806, ['user_spendings'])
top_min = avg_cust_data.nsmallest(10806, ['user_spendings'])

avg_cust_data['spendings_flag'] = np.where(avg_cust_data['user_spendings'] = top_max, 'Top Max',
                                  np.where(avg_cust_data['user_spendings'] = top_min, 'Top Min', 'AVG'))
Run Code Online (Sandbox Code Playgroud)

python sorting pandas

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

标签 统计

pandas ×1

python ×1

sorting ×1