使用groupby我现在卡在没有索引的情况下打印我的测试。
存储testdf时是否有任何选项可以避免索引?
g = df2.groupby('genome')['accession'].apply(list).reset_index()
testdf = g.join(pd.get_dummies(g['accession'].apply(pd.Series).stack()).sum(level=0)).drop('accession', 1)
print testdf
genome VFG000475 VFG000477 VFG000478 VFG000670 VFG000926
0 GCA_000367685.2 0 1 1 0 0
1 GCF_000026185.1 0 1 1 0 0
2 GCF_000026985.1 0 0 0 0 0
因为要将它保存为执行testdf.to_csv的.csv,它的工作原理如下:
testdf.to_csv(outName, sep='\t', header=True, index=False)
它没有索引保存:
genome VFG000475 VFG000477
GCA_000367685.2 0 1
GCF_000026185.1 0 1
在我看来,你想要没有索引列的print
你的df。
为此,请使用:
print testdf.to_string(index=False)