将序列添加到数据帧列表中的数据帧中时出现问题

2024-10-01 00:32:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据帧的集合,(即集群)存储在一个列表中

目标:我需要将一个序列对象remaining_attr[i]添加到具有最高规范化互信息分数的数据帧cluster

我的问题是,我通过将最佳集群存储在变量best_cluster中来跟踪它。这只是返回一个新的数据帧,而不是列表中包含的数据帧,即cluster_list[cluster]。在存储中间变量best_cluster: TypeError: list indices must be integers or slices, not DataFrame时,我还收到了错误消息

如何将series对象添加到列表中的max_nmis数据帧中

for i in remaining_attr:
    max_nmis = 0
    for cluster in cluster_list:
        for j in cluster:
            nmis = nmis(remaining_attr[i], cluster[j], average_method='arithmetic')
        if nmis > max_nmis:
            max_nmis = nmis
            best_cluster = cluster_list[cluster] <---------the problem 
    best_cluster.join(remaining_attr[i], inplace = True)

Tags: 数据对象in目标列表for集群序列