python读取excel数据共现问题。

img
我想要讨论哪两个p值成对出现的频率更大。比如,编号为1中,p1 p2, p1 p3, p1 p4 , p2 p3,p2p4,p3p4成对出现。如何实现对这些频率的统计,并按顺序输出

你这个是组合计算问题,可以参考下:https://blog.csdn.net/weixin_41481113/article/details/82845269

如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢

这样操作即可,

import pandas as pd
from itertools import combinations
df=pd.read_excel('78.xlsx')
def comb(x):
    x=x.split(',')
    num=combinations(x,2)
    return len(list(num))
df['组合数']=df['组合'].apply(comb)
res = df.iloc[df['组合数'].argmax()]
print(res)

如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳,谢谢