从2D字典中,如何将其转换为数据框或存在/不存在的矩阵,其中列表中的值是列,键是行名?我将目标列表中的值累加到一个矩阵中。
我一直在尝试,但是没有成功:
values = set()
for genome, info in dict_cluster.items():
for v in info:
#t = [genome, ([v for v in info])]
t = [genome,v]
print pd.DataFrame(t)
输入:
A ['arylpolyene', 'hserlactone', 'hserlactone', 'nrps', 'siderophore', 't1pks-nrps', 'terpene', 'thiopeptide', 'transatpks-nrps']
B ['hserlactone', 'hserlactone-arylpolyene', 'nrps', 'siderophore', 'thiopeptide']
C ['nrps', 'nrps', 'nrps', 'siderophore', 't1pks-nrps', 't1pks-nrps']
D ['nrps', 'siderophore', 't1pks-nrps']
输出:
arylpolyene siderophore hserlactone-arylpolyene transatpks-nrps terpene thiopeptide hserlactone nrps t1pks-nrps
A 1 2 0 1 1 1 2 1 1
B 0 1 1 0 0 1 1 1 0
C 0 1 0 0 0 0 0 3 2
D 0 1 0 0 0 0 0 1 1
我的输出是这样的:
0
0 GCF_900068895.1
1 transatpks-nrps
0
0 GCA_002415165.1
1 thiopeptide
0
0 GCA_000367685.2
1 t1pks-nrps
0
0 GCA_002732135.1
1 t1pks-nrps
吃鸡游戏
侃侃无极
相关分类