import pandas as pd
import numpy as np
aa = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
bb = [10, 21, 10, 21, 21, 10, 23, 23, 25, 25]
cc = [0, 1, 1, 2, 0, 0, 2, 2, 0, 0]
dd = [1, 2, 2, 4, 1, 6, 7, 8, 9, 10]
ee = [10, 21, 21, 21, 10, 10, 23, 23, 25, 25]
ff = [0, 1, 1, 2, 0, 0, 2, 2, 0, 0]
gg = [10, 21, 21, 21, 10, 10, 23, 23, 25, 25]
df_ = pd.DataFrame({'id': aa, 'source': bb, 'target': cc, 'x_source': dd, 'x_target': ee, 'y_source': ff, 'y_target': gg})
#
print(df_)
print(len(df_))
# 剔除重复的数据
# df_.drop_duplicates(subset=['x_source', 'x_target', 'y_source', 'y_target'], inplace=True)
# print(df_)
# print(len(df_))
# 获取除了第一次出现以外的重复行
df__ = df_[df_.duplicated(subset=['x_source', 'x_target', 'y_source', 'y_target'])]
print(df__)
print(len(df__))
剔除多列相同的数据,或者挑出多列重复的数据
本文展示了如何使用Python的Pandas库对数据集进行操作,包括创建DataFrame,检查并剔除重复的(x_source,x_target,y_source,y_target)组合,以及获取第一次出现后的重复行。
摘要由CSDN通过智能技术生成