Pandas printing in jupyter

Thomas Jollans tjol at tjol.eu
Thu Jan 11 04:19:01 EST 2018


On 2018-01-11 09:59, Rustom Mody wrote:
> On Thursday, January 11, 2018 at 2:13:46 PM UTC+5:30, Paul  Moore wrote:
>> The HTML representation is supplied by the object's _repr_html_
>> method. See https://ipython.org/ipython-doc/3/config/integrating.html
>> for some details.
>>
>>>>> import pandas as pd
>>>>> df = pd.DataFrame()
>>>>> df._repr_html_()
>> '<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type 
>> etc
> 
> Thanks — Useful direction
> So is there some ipython related restricted set of special (dunder-like) methods?
> 


The ‘moral equivalent of print()’* in IPython is display(), which is
documented here:
https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#IPython.display.display

It checks a list of special methods, which are listed in those docs.

Note that these days display() is available by default in all IPython
(notebook or non-notebook) sessions; in the past it had to be imported.

On a different note somewhat related to your original question: If you
want more control over how a DataFrame is displayed, you can have it:
https://pandas.pydata.org/pandas-docs/stable/style.html

-- Thomas


* direct quote from
https://blog.jupyter.org/release-of-ipython-5-4-6-1-and-rlipython-a5776b536899



More information about the Python-list mailing list