TypeError:只能将列表(而不是“元组”)连接到列表

我有两个Python Pandas DataFrame。每个DataFrame具有相同的列。一个df包含具有目标标签的历史数据,另一个df包含具有预测标签的当前数据的预测。

我的目标是针对与历史数据有关的每个预测数据单独运行KDTree查询,以从历史数据中获取三个最接近的邻居的列表。

我用于执行此操作的逻辑是for循环,该循环将当前数据中的一行添加到历史数据中,运行查询,然后将下一行添加到历史数据中。

这是我的代码:

fde = fde[features]
locations = []
for row in fde.iterrows():
    temp_elite = fne[features]
    temp_elite = temp_elite.append(row)
    tree = KDTree(temp_elite,metric='euclidean')
    dist,ind = tree.query(temp_elite,k=4)
    print(ind)
    locations.append(ind.tail(1))
print(locations)

但是,这是我的错!

---> 14     temp_elite = temp_elite.append(row)
TypeError: can only concatenate list (not "tuple") to list

我是否试图正确解决问题,以及有关如何解决此错误的任何想法?

cxlovexby 回答:TypeError:只能将列表(而不是“元组”)连接到列表

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2890007.html

大家都在问