Using groupby I stucked at the moment to print my testdf without the indexes.
Is there any option to avoid indexes when storing 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
Because to save it as .csv doing testdf.to_csv it works:
testdf.to_csv(outName, sep='\t', header=True, index=False)
And it is saved without indexes:
genome VFG000475 VFG000477
GCA_000367685.2 0 1
GCF_000026185.1 0 1
It seems to me that you want to print
your df without the index column.
To do so use:
print testdf.to_string(index=False)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.