A punchcard plot, also called a table bubble chart, is a type of visualization for highlighting cyclical trends in data. It displays data in a rigid matrix أو grid format, usually composed of days of the week versus hours of the day. Circles represent data points at the intersections of the rows and columns and their size conveys the data value. Color can be used to include additional information.
The name “punchcard” is an allusion to old-timey “timecards” that workers would stamp or “punch” in a machine to record their comings and goings.
To build a punchcard plot, you need timestamped data. In this Quick Success Data Science project, we’ll use a Kaggle dataset to track the times when bicycles are rented in Washington, D.C.
The Kaggle Bike Sharing in Washington D.C. Dataset contains the hourly and daily count of bikes rented in 2011 and 2012 in the Capital bikeshare system in Washington, D.C. . This data is released under a CC0 1.0 license. For details about the dataset contents visit the readme file.
For convenience, I’ve already downloaded this data to a public Gist.
Besides Python, you’ll need the pandas data analysis library and the seaborn plotting library. You can install them with:
conda install pandas seaborn
pip install pandas seaborn
The following commented code was written in JupyterLab and is described by cell.
Importing Libraries and Loading the Data
After importing matplotlib and seaborn for plotting and pandas for data analysis, we’ll read the CSV file of rental data into a pandas DataFrame, keeping only the columns for the season of the year, the weekday, the hour, and the count (number of rentals).