我在行“ added_parts = new_part_set [(new_part_set [“ duplicate”] == False)&(new_part_set [“ version”] ==“ target”)]“ **下得到E712的薄片8错误。 / p>
以下是我们用于电子表格比较的代码段
source_df = pd.read_excel(self.source, sheet).fillna('NA')
target_df = pd.read_excel(self.target, sheet).fillna('NA')
file_path = os.path.dirname(self.source)
column_list = source_df.columns.tolist()
source_df['version'] = "source"
target_df['version'] = "target"
source_df.sort_values(by=unique_col)
source_df = source_df.reindex()
target_df.sort_values(by=unique_col)
target_df = target_df.reindex()
# full_set = pd.concat([source_df, target_df], ignore_index=True)
diff_panel = pd.concat([source_df, target_df],
axis='columns', keys=['df1', 'df2'], join='outer', sort=False)
diff_output = diff_panel.apply(self.__report_diff, axis=0)
diff_output['has_change'] = diff_output.apply(self.__has_change)
full_set = pd.concat([source_df, target_df], ignore_index=True)
changes = full_set.drop_duplicates(subset=column_list, keep='last')
dupe_records = changes.set_index(unique_col).index.unique()
changes['duplicate'] = changes[unique_col].isin(dupe_records)
removed_parts = changes[(changes["duplicate"] == False) & (changes["version"] == "source")]
new_part_set = full_set.drop_duplicates(subset=column_list, keep='last')
new_part_set['duplicate'] = new_part_set[unique_col].isin(dupe_records)
added_parts = new_part_set[(new_part_set["duplicate"] == False) & (new_part_set["version"] == "target")]
diff_file = file_path + "file_diff.xlsx"
if os.path.exists(diff_file):
os.remove(diff_file)
writer = pd.ExcelWriter(file_path + "file_diff.xlsx")
diff_output.to_excel(writer, "changed")
removed_parts.to_excel(writer, "removed", index=False, columns=column_list)
added_parts.to_excel(writer, "added", index=False, columns=column_list)
writer.save()
还有其他方法可以避免这种情况吗?不确定是否继续进行。
答案 0 :(得分:0)
在DataFrame掩码中,您有172.19.0.2:8080
172.19.0.3:8080
和server server-a server-a:8080 check
server server-b server-b:8080 check
flake8建议您更改这些掩码。它抱怨的原因是在python中,使用(changes["duplicate"] == False)
运算符与布尔值进行比较被认为是不好的做法,而应该编写(new_part_set["duplicate"] == False)
和==
等。在熊猫中,如果您具有布尔值系列,您可以使用if my_bool:...
运算符取反,这样就可以编写新的蒙版了:
if not my_bool:...