gpt4 book ai didi

python - 获取字典值的 value_counts()

转载 作者:太空宇宙 更新时间:2023-11-04 06:54:00 25 4
gpt4 key购买 nike

<分区>

我很熟悉如何返回value_counts来自 pd.Series。但是,如何从字典的值中获取值计数?

假设我在字典 L 中有以下元组:

L = {1: (13600, 14797),
2: (14700, 14700),
3: (14700, 10400),
4: (14600, 17200),
5: (13600, 14797),
6: (14600, 17200),
7: (14700, 10400),
8: (14700, 10400),
9: (12800, 14770)}

如何从 L 中获取 value_counts,如下所示:

(14700, 10400) 3
(13600, 14797) 2
(14600, 17200) 2
(14700, 14700) 1
(12800, 14770) 1

这就是我目前所拥有的。但是,我认为字典键 1-9 妨碍了我,因为我收到错误 list object is not callable.

list = [(k, v) for k, v in L.items()] 
S = set(L)
F = {}
for i in list(S):
F[i] = list.count(i)

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com