1

I have a data set taken from kaggle, and I want to get the result shown here

enter image description here

So, I took that code, changed it a bit and what I ran is this:

# get titanic & test csv files as a DataFrame
titanic_df = pd.read_csv("./input/train.csv")
test_df    = pd.read_csv("./input/test.csv")

# preview the data
print titanic_df.head()

This works, as it outputs the right data, but not as neatly as in the tutorial... Can I make it right?

Here is my output (Python 2, Spyder):

enter image description here

Brian
  • 2,163
  • 1
  • 14
  • 26
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
  • 5
    The output you see is the output from ipython in jupyter as a web page, it looks like you're seeing the text output which is different as it's console based. Basically what you want is this: https://ipython.org/ipython-doc/3/notebook/notebook.html#htmlnotebook – EdChum May 09 '18 at 12:34
  • Shouldn't the console at least print it in one line (not using the '\')? – CIsForCookies May 09 '18 at 12:35
  • 2
    No, the default pandas options limits the max width of the output, it's decided to wrap around as it exceeds the limits. See [pd.set_option](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.set_option.html) in particular the `display.` params You can increase the `'max_colwidth'` and `'line_width'` params to not wrap it – EdChum May 09 '18 at 12:37
  • Are you sure you are using Spyder? Spyder should have a nice interface, unlike your picture. – Ken T May 09 '18 at 12:47
  • @EdChum Thanks! that did it. Want to add it as an answer, or should I? – CIsForCookies May 09 '18 at 12:48
  • 1
    Well if all you wanted was to not wrap the content then [this](https://stackoverflow.com/questions/26277757/pandas-to-html-truncates-string-contents) could be considered a dupe or [this](https://stackoverflow.com/questions/11707586/python-pandas-how-to-widen-output-display-to-see-more-columns) – EdChum May 09 '18 at 12:49

1 Answers1

1

Try using Jupyter notebook if you have not used it before. In ipython console, it will wrap the text and show it in multiple lines. In kaggle, what you are seeing is itself a jupyter notebook.

rawwar
  • 4,834
  • 9
  • 32
  • 57