2014-09-24 65 views
1

我有这样打印一个熊猫数据帧到一个文本文件(Python 3中)

Words 
One 
Two 
Three 
.... 
Threethousand 

我试图打印此列表与此代码的文本文件,一个大的数据文件:

df1 = df[['Words']] 
with open('atextfile.txt', 'w', encoding='utf-8') as outfile: 
     print(df1, file=outfile) 

但发生的事情是,它并没有打印出整个DF,它结束了看起来像这样:

Words 
One 
Two 
Three 
.... 
Threethousand 
Fourthousand 
Fivethousand 

我怎样才能打印出整个d F?

回答

1

我会用to_string要做到这一点,它不会像缩写印刷:

df['Words'].to_string('atextfile.txt') 
# or 
df[['Words']].to_string('atextfile.txt') 
+0

谢谢安迪! – user3682157 2014-09-25 02:19:18

相关问题