2

I am trying to use pandas to display data in a table format and for some reason, my last column is running off and being placed under the table instead of being on the far right of the table. I drew a picture of what the output ends up looking like. It also has a '\' right before the last column name for some reason. Is my table just too long horizontally? Any help is appreciated!

enter image description here

here's the code for this ('data' is a tuple w/ 8 elements):

pandas.set_option('display.max_rows', None)
pandas.set_option('display.max_columns', None)

df = pandas.DataFrame.from_records(data, columns=['Col1', 'Col2', 'Col3', 'Col4', 'Col5', 'Col6', 'Col7', 'Col8'])

print(df)
Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
BWallDev
  • 345
  • 3
  • 13

1 Answers1

5

see the pandas docs on options and settings.

You should be setting display.width not display.max_columns. From the docs:

display.max_columns (default 0 or 20):

max_rows and max_columns are used in repr() methods to decide if to_string() or info() is used to render an object to a string. In case Python/IPython is running in a terminal this is set to 0 by default and pandas will correctly auto-detect the width of the terminal and switch to a smaller format in case all columns would not fit vertically. The IPython notebook, IPython qtconsole, or IDLE do not run in a terminal and hence it is not possible to do correct auto-detection, in which case the default is set to 20. ‘None’ value means unlimited.

display.width (default 80):

Width of the display in characters. In case Python/IPython is running in a terminal this can be set to None and pandas will correctly auto-detect the width. Note that the IPython notebook, IPython qtconsole, or IDLE do not run in a terminal and hence it is not possible to correctly detect the width.

display.max_columns sets the total number of columns to display, which includes wrapped columns. display.width tells pandas how many columns/characters to use when displaying each row of a dataframe's repr.

Note that this is purely a discussion of the display - the data itself is not being placed at the bottom of the table.

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
  • thank you! Editing the width allowed everything to fit how I wanted it to! – BWallDev Aug 05 '21 at 04:18
  • 1
    glad it helped! rather than changing the question name to [solved], on stack overflow the convention is to select the correct answer. check out the [tour](https://stackoverflow.com/tour). welcome! – Michael Delgado Aug 05 '21 at 04:24