-2

I can't seem to figure out how to display all columns in this .data file. I can only display two separate columns when I'd like to display all ten.

I've attached an image with what I've tried. I've been looking over for the documentation, but nothing seems to fit.

I've also attached an image with how I'd like the data to display in jupyter notebook.

How I'd like to display the data:

How I'd like to display the data (screenshot)

How I'd like to display the data:

18.0   8   307.0      130.0      3504.      12.0   70  1    "chevrolet mal"
15.0   8   350.0      165.0      3693.      11.5   70  1    "buick skylark"
18.0   8   318.0      150.0      3436.      11.0   70  1    "plymouth sat"
16.0   8   304.0      150.0      3433.      12.0   70  1    "amc rebel sst"
17.0   8   302.0      140.0      3449.      10.5   70  1    "ford torino"
15.0   8   429.0      198.0      4341.      10.0   70  1    "ford galaxie"
14.0   8   454.0      220.0      4354.       9.0   70  1    "chevrolet"
14.0   8   440.0      215.0      4312.       8.5   70  1    "plymouth fury" 
14.0   8   455.0      225.0      4425.      10.0   70  1    "pontiac"

What I've tried so far:

    import pandas as pd

    pd.set_option('display.max_rows', None)
    pd.set_option('display.max_columns', None)
    pd.read_table('auto-mpg.data', header=None)

    0   1
0   18.0 8 307.0 130.0 3504. 12...  chevrolet chevelle malibu
1   15.0 8 350.0 165.0 3693. 11...  buick skylark 320
2   18.0 8 318.0 150.0 3436. 11...  plymouth satellite
3   16.0 8 304.0 150.0 3433. 12...  amc rebel sst
4   17.0 8 302.0 140.0 3449. 10...  ford torino
5   15.0 8 429.0 198.0 4341. 10...  ford galaxie 500
6   14.0 8 454.0 220.0 4354. 9...   chevrolet impala
7   14.0 8 440.0 215.0 4312. 8...   plymouth fury iii
8   14.0 8 455.0 225.0 4425. 10...  pontiac catalina
9   15.0 8 390.0 190.0 3850. 8...   amc ambassador dpl
10  15.0 8 383.0 170.0 3563. 10...  dodge challenger se

The table is truncated as pandas attempts to display the data in two columns.

enter image description here

smci
  • 32,567
  • 20
  • 113
  • 146
sol
  • 13
  • 5
  • 2
    Welcome to SO! Try posting your data and code as a text instead of images or links to images. It may help people to come up with a solution quickier. – Sergey Bushmanov Jan 16 '20 at 12:09
  • Try ```df = pd.read_table(table_name) df.head()``` – Hayat Jan 16 '20 at 12:15
  • Does this answer your question? [How to read file with space separated values in pandas](https://stackoverflow.com/questions/19632075/how-to-read-file-with-space-separated-values-in-pandas) – smci Jan 16 '20 at 12:30

1 Answers1

0

pandas is attempting to display the data in two columns because you inadvertently told pandas to read it in as two columns.

  • First, all the numeric columns are being read into one single column '0'. The telltale is you can see you get 18.0 8 307.0 130.0 3504. 12... all under column '0', which is wrong. Because your file's delimiter is space, not comma (CSV).
  • Second: don't accuse pandas over jupyter; don't say "pandas isn't displaying..."
    • Run in a plain Python console session (no jupyter, no browser) to see what pandas actually does or doesn't display. Debug that first.
    • Only when you've debugged that, then run in jupyter notebook. jupyter notebook layers its own (browser-based) rendering functionality on top of Python/pandas, and will massage the output from pandas, sometimes in annoying ways. It's a bad idea to try to debug both at the same time.
smci
  • 32,567
  • 20
  • 113
  • 146