Inspect Data Types

Understand the various data types that exist within pandas.

Motivation

There are several reasons why it’s important to check and understand the data types in our data:

  • Certain operations and functions can only be applied to certain data types. For example, mathematical operations can only be performed on numerical data, and alphabetical sorting can only be performed on string (text) data.

  • Some machine learning models can only receive certain compatible data types as input.

  • Memory usage (in certain occasions) can potentially be reduced by using data types that require less memory for storage.

  • Errors and inconsistencies can be identified upon manual checks of the data types—for example, finding that a data type doesn’t match the column description.

Suppose we have the following DataFrame with two columns, A and B. The two columns appear to have numerical values, but let's see what we’ll get when we sum the values across the two columns.

Get hands-on with 1200+ tech skills courses.