Scrpit R with pandas



我实际上使用R删除了重复的序列,例如:

seq1      seq2 
seq2      seq1 
seq3      seq4 
seq5      seq6

并得到

seq1      seq2
seq3      seq4 
seq5      seq6

通过做:

data<-read.table("dataframe.txt")
for (i in 1:nrow(data))
{
data[i,c(2,3)] = sort(data[i,c(2,3)])
}
data2 = data[!duplicated(data[,c(2,3)]),]
write.csv(data2,"data_without_duplicated")

有人知道如何用熊猫做吗?

以下是真实数据的示例:

cluster_name    qseqid  sseqid  pident_x    pident_y    length  qstart  qend    sstart  send    qspec   sspec
13  cluster_016663  EOG090X00GO_0035_0035_1 EOG090X00GO_0042_0035_1 0.93    93.0    1179    1   1175    1   1179    0035    0042
14  cluster_016663  EOG090X00GO_0035_0035_1 EOG090X00GO_0042_0042_1 0.93    93.0    1179    1   1175    1   1179    0035    0042
16  cluster_016663  EOG090X00GO_0035_0042_1 EOG090X00GO_0042_0035_1 0.93    93.0    1179    1   1175    1   1179    0035    0042
17  cluster_016663  EOG090X00GO_0035_0042_1 EOG090X00GO_0042_0042_1 0.93    93.0    1179    1   1175    1   1179    0035    0042
19  cluster_016663  EOG090X00GO_0042_0035_1 EOG090X00GO_0035_0035_1 0.93    93.0    1179    1   1179    1   1175    0042    0035
20  cluster_016663  EOG090X00GO_0042_0035_1 EOG090X00GO_0035_0042_1 0.93    93.0    1179    1   1179    1   1175    0042    0035
22  cluster_016663  EOG090X00GO_0042_0042_1 EOG090X00GO_0035_0035_1 0.93    93.0    1179    1   1179    1   1175    0042    0035
23  cluster_016663  EOG090X00GO_0042_0042_1 EOG090X00GO_0035_0042_1 0.93    93.0    1179    1   1179    1   1175    0042    0035

这是我的脚本:

data_wo_eqSpec.to_csv("dataframe.txt", sep='t')
print("prem1:",data_wo_eqSpec.shape)
data_wo_eqSpec=data_wo_eqSpec.astype(str) 
data_wo_eqSpec.iloc[:,1:3]=np.sort(data_wo_eqSpec.iloc[:,1:3].values,1)
data_wo_eqSpec2= data_wo_eqSpec.drop_duplicates(list(data_wo_eqSpec.iloc[:,1:3]))
print("prem:",data_wo_eqSpec2.shape)
data_wo_eqSpec=pd.read_csv("data_without_duplicated")
print("deus:",data_wo_eqSpec.shape)

以下是数据:数据

ForPython

data.iloc[:,2:4]=np.sort(data.iloc[:,2:4].values,1)
data2 = data.drop_duplicates(list(data.iloc[:,2:4]))

对于没有 for 循环的 R,使用apply

df[!duplicated(t(apply(df[,c(1,2)],1,sort))),]

最新更新