我想在python中实现纯度测量

时间:2018-07-12 13:11:21

标签: python excel

我想在python中实现纯度测量,我有一个像这样的excel文件: enter image description here

数字是笔记本电脑的群集。我想获得每个群集的笔记本电脑数量,如下所示: enter image description here

你能帮我吗?

1 个答案:

答案 0 :(得分:0)

在excel文件中,将两列连接起来,然后再使用python分析。如果您的数据在excel中的A和B列中,则可以使用以下公式进行连接:

=Concatenate(A1,", ",B1)

这是结果:

Concatenated columns

现在您已经将每个品牌及其簇号组合在一起,可以运行一个简单的python脚本来计算每个字符串出现的次数。

用于python的伪代码:

d = dict()

For each row in concatenated column:
    If string in d: #checking if dictionary key already exists for this computer-cluster combo
        d[string] += 1 #add 1 if exists already
    else:
        d[string] = 1 #create key and assign value of 1 if key does not exist already

print(d)
相关问题