1

I have a large data file like this

 Words
 One
 Two
 Three
 ....
 Threethousand

I am trying to print this list to a text file with this code:

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

But what happens is that it doesn't print out the whole DF, it ends up looking like this:

 Words
 One
 Two
 Three
 ....
 Threethousand
 Fourthousand
 Fivethousand

How can I print out the whole DF?

1 Answer 1

2

I would use to_string to do this, it doesn't abbreviate like the printing:

df['Words'].to_string('atextfile.txt')
# or
df[['Words']].to_string('atextfile.txt')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.