的程序,我有工作输出结果outputed制表符分隔的文件看起来像这样:使用熊猫下令每隔两行
marker A B C
Bin_1 1 2 1
marker C G H B T
Bin_2 3 1 1 1 2
marker B H T Z Y A C
Bin_3 1 1 2 1 3 4 5
我想,这样它看起来像这样来解决它:
marker A B C G H T Y Z
Bin_1 1 2 1 0 0 0 0 0
Bin_2 0 1 3 1 1 1 0 0
Bin_3 4 1 5 0 1 2 3 1
这是我迄今为止
import pandas as pd
from collections import OrderedDict
df = pd.read_csv('markers.txt',header=None,sep='\t')
x = map(list,df.values)
list_of_dicts = []
s = 0
e =1
g = len(x)+1
while e < g:
new_dict = OrderedDict(zip(x[s],x[e]))
list_of_dicts.append(new_dict)
s += 2
e += 2
起初,我将这些以字典,然后WA我们要做一些计数并重新创建一个数据框,但这似乎需要花费大量的时间和内存来完成一项简单的任务。任何建议,以更好的方式来解决这个问题?