Displaying Pandas DataFrames Horizontally in Jupyter Notebooks

Ted Petrou
Dunder Data

--

In this tutorial, you’ll learn how to display pandas DataFrames horizontally in your Jupyter Notebooks. I find this useful when presenting data to an audience or when delivering tutorials like this one.

Default DataFrame Display

Let’s begin by reading in three different DataFrames, assigning them to variable names. By default, nothing is displayed in the output when an assignment statement is the last line of a notebook cell.

import pandas as pd
bikes = pd.read_csv('bikes.csv', nrows=3)
flights = pd.read_csv('flights.csv', nrows=3)
housing = pd.read_csv('housing.csv', nrows=3)

If the variable name is displayed as the last line in a notebook, then it will be displayed in the output. Here, we output the bikes DataFrame.

bikes
png

If there is any non-comment line beneath the DataFrame, then it won’t be displayed in the cell. Here, we perform a simple arithmetic operation as our last line which gets evaluated and output.

The print function may be used to output other lines that do not appear as the last line…

--

--

Ted Petrou
Dunder Data

Author of Master Data Analysis with Python and Founder of Dunder Data