Skip to content

Instantly share code, notes, and snippets.

@dmyersturnbull
Last active July 6, 2016 23:05
Show Gist options
  • Save dmyersturnbull/035876942070ced4c565e4e96161be3e to your computer and use it in GitHub Desktop.
Save dmyersturnbull/035876942070ced4c565e4e96161be3e to your computer and use it in GitHub Desktop.
Pretty-print the head of a Pandas table in a Jupyter notebook and show its dimensions. Allows showing multiple tables per cell.
from IPython.display import display, Markdown
import pandas as pd
def head(df: pd.DataFrame, n_rows:int=1) -> None:
"""Pretty-print the head of a Pandas table in a Jupyter notebook and show its dimensions."""
display(Markdown("**whole table (below):** {} rows × {} columns".format(len(df), len(df.columns))))
display(df.head(n_rows))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment