Я пытаюсь перезаписать столбцы 1, если есть дубликаты, но по какой-то причине этот код не> перезаписывает 1, он делает что-то еще.
Пример ввода
dhid,midx,midy,midz,a,dtype
AAA1,321.235,200.436,59.72,7,RR
AAA7,321.235,200.436,59.72,-99,CR
AAA2,321.235,200.236,68.7,15,CR
Пример вывода:
dhid,midx,midy,midz,a,dtype,KEEPVA
AAA1,321.235,200.436,59.72,7,RR,1
AAA7,321.235,200.436,59.72,-99,CR,0 --> GETS RID OF THIS DUPLICATE THAT IS MISSING
AAA2,321.235,200.236,68.7,15,CR,1
Моя попытка пока
dup_dict = []
flg = False
for i in range(npts-1):
d2 = 0.0
for idir in range(2,-2,-1):
if (idir==-1 and d2 <= d2tol ):
dup_dict.append([i,i+1,d2])
break
d = np.abs(xyz[i,idir]-xyz[i+1,idir])
if (d > dtol):
break
d2 = d2 + d ** 2
print('Total Duplicates Found: %d'%(len(dup_dict)))
df['KEEPVA'] = np.ones(len(df.index))
fmtlist = ['%s','%0.5f','%0.5f','%0.5f','%0.5f','%d','%s']
fl = open('dup_gq.log','w')
fl.write(','.join(['dhid','midx','midy','midz','a','KEEPVA','dtype'])+'\n')
for i0,i1,d in dup_dict:
aufa0 = df['a'].values[i0]
aufa1 = df['a'].values[i1]
dtype0 = df['dtype'].values[i0]
dtype1 = df['dtype'].values[i1]
if (dtype0!=dtype1):
print(df['dhid'].values[i0],df['dhid'].values[i1],dtype0,dtype1,a0,a1)
if a0 > a1:
df.loc[i1,'KEEPVA'] = 0
if a0 <= a1:
df.loc[i0,'KEEPVA'] = 0
print(df['dhid'].values[i0],df['dhid'].values[i1],df['KEEPVA'].values[i0],
df['KEEPVA'].values[i1])
a = df[['dhid','midx','midy','midz','a','KEEPVA','dtype']].values[[i0,i1],:]
np.savetxt(fl,a,fmt=fmtlist,delimiter=',')
fl.close()