2014-09-24 62 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

相關問題