0

I'm writing a summary and I need to write multiple pandas data frames to the same txt file. .to_csv method can only write one data frame to a file, so I tried the following code:

f = open('summary.txt', 'w')
f.write(str(df1))
f.write(str(df2))
f.write(str(df3))
f.close()

However, in the summary file, there were showed only parts of the data frames, most lines of each data frame were represented as ....

Jaroslav Bezděk
  • 4,527
  • 4
  • 23
  • 38
Henry Bai
  • 145
  • 9
  • Relevant, and possibly even duplicate: [Pretty-print an entire Pandas Series / DataFrame](https://stackoverflow.com/questions/19124601/pretty-print-an-entire-pandas-series-dataframe) – Amadan Sep 05 '19 at 07:45

1 Answers1

0

Try the following code:

with open('summary.txt', 'w') as f:
    f.write(df1.to_string())
    f.write(df2.to_string())
    f.write(df3.to_string())
Jaroslav Bezděk
  • 4,527
  • 4
  • 23
  • 38