chapter eight

8 Analyzing Tables Using Pandas

 

This section covers:

  • Storing 2D tables using the Pandas library
  • Summarizing 2D table content
  • Manipulating row and column content
  • Visualizing tables using the Seaborn library

The ad-click data for Case Study Two is saved in a 2-dimensional table. Data tables are commonly used to store information. The tables may be stored in different formats. Some tables are saved as spreadsheets in Excel. Other tables are text-based CSV files where the columns are separated by commas. The formatting of a table isn’t important. What is important is its structure. All tables have structural features in common. Every table contains horizontal rows and vertical columns. Quite often, column headers also hold explicit column names.

8.1  Storing Tables Using Basic Python

Let’s define a sample table in Python. The table will store measurements for various species of fish. The measurements will cover both length and width, in centimeters. Our measurement table will contain three columns: Fish, Length, and Width. The Fish column will store a labeled species of fish. The Length and Width columns will specify the length and width of each fish species. We’ll represent this table as a dictionary. The column names will serve as dictionary keys. These keys will map to lists of column values. Let’s proceed to build our fish_measures table.

8.2  Exploring Tables Using Pandas

8.3  Retrieving Table Columns

8.4  Retrieving Table Rows

8.5  Modifying Table Rows and Columns

8.6  Saving and Loading Table Data

8.7  Visualizing Tables Using Seaborn

8.8  Summary