Scrpit R与熊猫

时间:2018-05-09 21:02:50

标签: r 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)

以下是数据:data

0 个答案:

没有答案