gpt4 book ai didi

python - 如何在python中的数据框中查找具有相同值的列列表

转载 作者:行者123 更新时间:2023-12-04 16:42:15 25 4
gpt4 key购买 nike

我正在尝试在数据框中查找列中具有相同值的列列表。 R whichAreInDouble 中有一个包,试图在 python 中实现它。

df  =   
a b c d e f g h i
1 2 3 4 1 2 3 4 5
2 3 4 5 2 3 4 5 6
3 4 5 6 3 4 5 6 7

它应该给我具有相同值的列列表喜欢

a, e are equal
b,f are equal
c,g are equal

最佳答案

让我们尝试使用 itertools 和组合:

from itertools import combinations

[(i, j) for i,j in combinations(df, 2) if df[i].equals(df[j])]

输出:

[('a', 'e'), ('b', 'f'), ('c', 'g'), ('d', 'h')]

关于python - 如何在python中的数据框中查找具有相同值的列列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57997817/

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