Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Changing the Data Type | Brief Introduction
Data Preprocessing

Changing the Data TypeChanging the Data Type

You already know how to change the data type from string to number, for example. But let's take a closer look at this small but important task.

Let's start by changing the data type from string to datetime. Most often, you will need this to work with time series. You can perform this operation using the .to_datetime() method:

To convert a string to a bool - use the .map() method on the column whose values you want to change:

For example, if you have a price column that looks like "$198,800" and you want to turn it into a float - you should create custom transformation functions:

Task

Read the sales_data_types.csv dataset and change the data type in the Active column from str to bool.

Everything was clear?

Section 1. Chapter 5
toggle bottom row
course content

Course Content

Data Preprocessing

Changing the Data TypeChanging the Data Type

You already know how to change the data type from string to number, for example. But let's take a closer look at this small but important task.

Let's start by changing the data type from string to datetime. Most often, you will need this to work with time series. You can perform this operation using the .to_datetime() method:

To convert a string to a bool - use the .map() method on the column whose values you want to change:

For example, if you have a price column that looks like "$198,800" and you want to turn it into a float - you should create custom transformation functions:

Task

Read the sales_data_types.csv dataset and change the data type in the Active column from str to bool.

Everything was clear?

Section 1. Chapter 5
toggle bottom row
some-alt