7. Data Types

7.1 Introduction

Data types determine what can and cannot be done to a variable (i.e., column). For example, when numeric data types are added together, the result will be a sum of the values; in contrast, if strings (in Pandas they are called object) are added, the strings will be concatenated together.

This chapter presents a quick overview of the various data types you may encounter in Pandas, and means to convert from one data type to another.

Objectives

This chapter will cover:

1. Finding the data types of columns in a dataframe

2. Converting between various data types

3. Working with the categorical data type

Working with dates and times is covered in Chapter 11.

7.2 Data Types

In this chapter, we’ll use the built-in ...

Get Pandas for Everyone: Python Data Analysis, First Edition 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.