eran
eran

Reputation: 15136

print a pandas dataframe to text with lines longer than 80 chars

I want to print a Dataframe to a text file,

Say I have a table with 4 lines, and 12 columns.

It looks quite nice when I just use print df, with all the values of a column aligned to the right, however, when there are too many columns (8 in my case) it breaks the table down so that the last 4 columns are printed after 4 lines of 8 values. Probably as Pandas tries to make the table fit in a 80 chars line.

I tried df.to_csv().replace(',','\t'), but then entries longer than a tab cause a jump in the line, and the lines are no longer aligned.

How can I get the nice, orderly, aligned to right, fashion, but not enforcing 80 characters per line?

Upvotes: 6

Views: 857

Answers (1)

hellpanderr
hellpanderr

Reputation: 5896

Try changing pandas.options.display.width. (It's 80 by default)

Upvotes: 6

Related Questions