Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use display() not print() to display a dataframe in a jupyter notebook! #342

Open
djinnome opened this issue Nov 1, 2018 · 16 comments
Open
Labels
type:discussion Discussion or feedback about the lesson

Comments

@djinnome
Copy link
Contributor

djinnome commented Nov 1, 2018

Hi folks,

I want to submit a pull request that removes all print() statements from the lesson, and at the very minimum, replaces them with display(). Jupyter notebooks by default display dataframes in an easy-to read html table, whereas the print function displays an ugly, hard-to-follow, poorly formatted ascii tab-separated output. If you want to view the value of the last line of a notebook cell, then you don't even need display(). Plus, once folks are familiar with from IPython.display import display, then it is logical to mention additional display outputs such as Image(), Latex() and SVG.

Please let me know what the probability of accepting this pull request would be before I go ahead and do the work.

Sincerely,

Jeremy

@vahtras
Copy link
Contributor

vahtras commented Nov 1, 2018

Good idea - I always use display in this context.
Olav

@gvwilson
Copy link
Contributor

gvwilson commented Nov 1, 2018

Making this change would weld us pretty firmly to the notebook as a teaching interface - I still don't introduce it until after the first coffee break because I find the cognitive load of a new kind of editing on top of learning a language is too much for some learners.

@vahtras
Copy link
Contributor

vahtras commented Nov 1, 2018

This particular lesson is already welded to the notebook as a teaching interface, isn't it?

@ntmoore
Copy link
Contributor

ntmoore commented Nov 1, 2018

I think a section introducing display() would be a good idea. It would be an especially good idea in the pandas section. I agree - the default printing of a pandas table is pretty ugly.

I think wholesale elimination of the print function is a bad idea. Why? Display does not work (so far as I can tell) from the python command line. This seems like a big missed idea if a learner is going to go on to writing python programs that live and are executed in the shell.

@Tillsa
Copy link

Tillsa commented Nov 20, 2018

I think introducing display() is generally a good idea, due to its easier to read output. And a clear tabular output of a DataFrame makes it easier for the human mind to process the information. But I agree with @ntmoore and @gvwilson that it should not be introduced to early, because learners should first get familiar with the basic print() function. A good point for introducing display() could be section "Reading Tabular Data into DataFrames", because of two reasons:

  1. In this section of the lesson the pandas DataFrame is introduced and display helps a lot to easily understand the structure of a DataFrame in a visual way.
  2. If the display() function is introduced by importing it like from IPython.display import display, this would be a nice repetition of the concept of importing libraries/modules of the previous section "Libraries"

@davidrpugh
Copy link

I would like to link issue #397 which proposes switching to JupyterLab from Jupyter notebook. Using JupyterLab instead of Jupyter notebook might help those instructors such as @gvwilson who teach Python from a console first and then introduce Jupyter notebooks later. Process of launching the Jupyter lab server is the same as launching the Jupyter notebook server..

$ jupyter lab

...instead of the following.

$ jupyter notebook

JupyterLab server UI is similar in many respects to RStudio UI. In particular, JupyterLab includes an IPython console/terminal as part of the UI which would help reduce the cognitive load for learners when switching between console and notebooks.

@alee alee added the type:discussion Discussion or feedback about the lesson label May 14, 2019
@ntmoore
Copy link
Contributor

ntmoore commented Jun 5, 2019

For now, I think the easiest way to address this issue is to add a small discussion of display() in episode 8, which works with dataframes. Display would be especially relevant here because print doesn't render dataframes nicely.

@djinnome
Copy link
Contributor Author

djinnome commented Jun 5, 2019

+1

1 similar comment
@vahtras
Copy link
Contributor

vahtras commented Jun 5, 2019

+1

@ntmoore
Copy link
Contributor

ntmoore commented Jun 5, 2019 via email

@djinnome
Copy link
Contributor Author

djinnome commented Jun 5, 2019

Actually, the discussion of display() should be in episode 7, Reading Tabular Data into DataFrames

@ntmoore
Copy link
Contributor

ntmoore commented Jun 5, 2019 via email

@FinancialRADDeveloper
Copy link

This solved my issue with having to separate cells in my notebook! Thanks so much

@shervinsahba
Copy link

shervinsahba commented Oct 2, 2019

What's the rationale of using display(df) when Jupyter Lab will pretty print the table when df is the last line in a cell? Wouldn't that be the cleanest approach?

Also, the only issue I can think of with replacing print() would occur when exporting .ipynb -> .py. Upon exporting, print() works out of the box but display() requires from IPython.core.display import display to function. But I don't think anyone is exporting these pandas notebooks... so it should be cool.

@Talha-Naeem
Copy link

not working sir,still open new tab

@Talha-Naeem
Copy link

%matplotlib inline
it works, and this command tell by my Sir Anees Ahmed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:discussion Discussion or feedback about the lesson
Projects
None yet
Development

No branches or pull requests

10 participants