Python 存储或打印不带索引的df.groupby

Python 存储或打印不带索引的df.groupby,python,matrix,pandas-groupby,Python,Matrix,Pandas Groupby,使用groupby,我当时在打印没有索引的testdf时遇到了麻烦 在存储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

使用groupby,我当时在打印没有索引的testdf时遇到了麻烦

在存储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 
因为要将其保存为.csv,请执行testdf.to_csv操作:

testdf.to_csv(outName, sep='\t', header=True, index=False)
并且保存时不带索引:

         genome VFG000475   VFG000477
GCA_000367685.2     0           1
GCF_000026185.1     0           1

在我看来,您似乎想要打印没有索引列的df

为此,请使用:

print testdf.to_string(index=False)