Lesson 10 of 10 · 2 min
Displaying Results as Tables in Jupyter
print() outputs plain ASCII text. display() renders HTML tables — much cleaner.
from IPython.display import display
| Situation | Old (bad) | New (good) |
|---|---|---|
| DataFrame | print(df) | display(df) |
| Series | print(series) | display(series.to_frame()) |
df.info() | df.info() | See pattern below |
| Dict | print(d) | display(pd.DataFrame(d.items(), columns=['Key','Value']).set_index('Key')) |
Replace df.info() with a table:
import pandas as pd
print(f"RangeIndex: {len(df):,} entries | {df.shape[1]} columns")
display(pd.DataFrame({
'Column': df.columns,
'Non-Null Count': df.count().values,
'Null Count': df.isnull().sum().values,
'Dtype': df.dtypes.astype(str).values
}).reset_index(drop=True))
Key rule: df.info() prints to stdout — it does NOT return a DataFrame, so you cannot wrap it in display(). Build the table manually instead.
