Creating a histogram for a column
A histogram is a graph that shows the distribution of numerical data. The matplotlib
Python library makes creating a histogram a snap. Here's how.
Getting ready
Before using this recipe, familiarize yourself with the following recipes as we'll be building on them:
- Creating a Pandas DataFrame from a MongoDB query
- Generating a frequency table for a single column by date
How to do it…
- To create a histogram for a single column in a Pandas DataFrame, begin by importing all the required libraries. To show
matplotlib
plots in IPython Notebook, we will use an IPython magic function which starts with%
:%matplotlib inline import pandas as pd import numpy as np from pymongo import MongoClient import matplotlib as mpl import matplotlib.pyplot ...
Get Python Business Intelligence Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.