我有一个带有数据框的列的列表: List of Columns and Values
Df = ["correct_New", "miss_New", "wrong_New", "correct_Old","miss_Old","wrong_Old"]
ListNew = ["correct_New", "miss_New", "wrong_New"]
ListOld = ["correct_Old","miss_Old","wrong_Old"]
#Dropping equivalent
df_merge_files = Df[ListNew] != Df[ListOld]
#Going to save only the differences.
df_merge_files.to_csv("comparison_report.csv", sep=';', index=False)
ValueError:只能比较标记相同的DataFrame对象
答案 0 :(得分:0)
尝试:
df_merge_files = Df[ListNew].rename(columns=dict(zip(ListNew, ListOld))) != Df[ListOld]
进行这种比较时,列名必须匹配。
或者,您也可以将它们都转换为numpy
并从那里工作:
df_merge_files = Df[ListNew].to_numpy() != Df[ListOld].to_numpy()