Generating a frequency table for a single column by date

A frequency table is another way of summarizing data; it shows the number of times a value occurs. In this recipe, we will create a frequency table of casualties by date.

Getting ready

To use this recipe, you need to have MongoDB running, and to have the accidents data imported.

How to do it…

  1. To generate a frequency table for a single column by date, begin by importing the Python libraries that we need:
    import pandas as pd
    import numpy as np
    from pymongo import MongoClient
  2. Next, connect to MongoDB, and run a query specifying the five fields to be retrieved from the MongoDB data:
    client = MongoClient('localhost', 27017) db = client.pythonbicookbook collection = db.accidents fields = {'Date':1, 'Police_Force':1, ...

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.