我有一个数据帧,其中有一些重复。它们位于每行特定数量的列索引中:
df_in
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19...
1 3 4 6 0 2 0 3 0 2 0 3 4 5 6 2 4 5 6 2...
.
.
在row 1
索引4-7
中有一个[0, 2, 0, 3]
索引8-11
的重复,然后从12-15
索引[4, 5, 6, 2]
有一个16-19
的重复。你知道吗
我需要的是检测每一行中的每个4 numbers
是否相等,如果相等,则从数据帧中删除其中一个重复。你知道吗
输出为:
df_out
0 1 2 3 4 5 6 7 8 9 10 11...
1 3 4 6 0 2 0 3 4 5 6 2...
.
.
psudo代码类似于:
for index in range(4, len(df_in.columns)):
if bool((df_in.iloc[:, index] == (df_in.iloc[:, index+4]).all()) == True:
remove either df_in.iloc[:, index] or df_in.iloc[:, index]+4 and keep one
if bool((df_in.iloc[:, index] == (df_in.iloc[:, index+4]).all()) == False:
keep df_in.iloc[:, index]
有没有一个简单的方法来完成这件事?你知道吗
这看起来是个疯狂的解决方案。主要思想是使用python的
hash
函数检查重复:相关问题 更多 >
编程相关推荐