6

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) 
6
  • That "\" means continuation, if you do it on a jupyter notebook / google colab you might see a scroll bar that allows you to move horizontally. Commented Aug 5, 2021 at 3:58
  • It's right. Your table is too long. That's why you have a '\' at the end. Commented Aug 5, 2021 at 3:58
  • @CeliusStingher oh okay I gotchya, thanks for the help! Commented Aug 5, 2021 at 4:00
  • @Corralien thanks, I was hoping that wasn't the case but it is what it is haha Commented Aug 5, 2021 at 4:01
  • 1
    Please don't edit "SOLVED" into the title - accept the answer. Commented Aug 5, 2021 at 4:24

1 Answer 1

14

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.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you! Editing the width allowed everything to fit how I wanted it to!
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. welcome!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.