Customer Name Segment Discount Profit
1 Jane Waco Corporate 0.2 1906.4850
2 Joseph Holt Consumer 0.4 -1862.3124
3 Greg Maxwell Corporate 0.0 83.2810
4 Thomas Boland Corporate 0.0 517.4793
5 Sue Ann Reed Consumer 0.2 341.9940
6 Karen Ferguson Home Office 0.2 363.9048
7 Joel Eaton Consumer 0.3 -350.4900
8 Nora Preis Consumer 0.2 135.4068 在简·韦科的交易中,她做了很多交易。每次购买都有不同的折扣金额。如何显示她购买时最常出现的折扣金额?在我制作的这组编码数据中,折扣列只显示最高值,但我想要最频繁的值
from collections import Counter
L = data["Discount"]
data.groupby('Customer Name')['Discount'].nunique()
maxi = Counter(data['Discount']).most_common(1)
data.iloc[1:24,[6,7,maxi,21,24,25]]折扣是索引20,但我不知道如何显示简·韦科收到的最频繁的折扣
发布于 2019-11-03 03:08:17
如果我没理解错你的问题..。它归结为一个问题,即如何获取列表中最常见的项。
l = [1, 2, 2, 3, 5, 7, 7, 7, 9, 9, 11, 12]
dic = dict([(str(i), 0) for i in l])
for value in l:
dic[str(value)] += 1
values = dic.items()
values.sort(key=lambda x: x[1])
most_common = values[-1][0]https://stackoverflow.com/questions/58674121
复制相似问题