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
course content

Зміст курсу

Data Preprocessing

Data Preprocessing

1. Brief Introduction
2. Processing Quantitative Data
3. Processing Categorical Data
4. Time Series Data Processing
5. Feature Engineering
6. Moving on to Tasks

bookChanging 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:

12345678910111213
import pandas as pd import re # Create simple dataset df = pd.DataFrame(data={'Price':['$4,122.94', '$1,002.3']}) # Create a custom function to transform data # x - value from column def price2int(x): return float(re.sub(r'[\$\,]', '', x)) # Use custom transformation on a column df['Price'] = df['Price'].apply(price2int)
copy
Завдання
test

Swipe to show code editor

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

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5
toggle bottom row

bookChanging 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:

12345678910111213
import pandas as pd import re # Create simple dataset df = pd.DataFrame(data={'Price':['$4,122.94', '$1,002.3']}) # Create a custom function to transform data # x - value from column def price2int(x): return float(re.sub(r'[\$\,]', '', x)) # Use custom transformation on a column df['Price'] = df['Price'].apply(price2int)
copy
Завдання
test

Swipe to show code editor

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

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5
toggle bottom row

bookChanging 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:

12345678910111213
import pandas as pd import re # Create simple dataset df = pd.DataFrame(data={'Price':['$4,122.94', '$1,002.3']}) # Create a custom function to transform data # x - value from column def price2int(x): return float(re.sub(r'[\$\,]', '', x)) # Use custom transformation on a column df['Price'] = df['Price'].apply(price2int)
copy
Завдання
test

Swipe to show code editor

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

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

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:

12345678910111213
import pandas as pd import re # Create simple dataset df = pd.DataFrame(data={'Price':['$4,122.94', '$1,002.3']}) # Create a custom function to transform data # x - value from column def price2int(x): return float(re.sub(r'[\$\,]', '', x)) # Use custom transformation on a column df['Price'] = df['Price'].apply(price2int)
copy
Завдання
test

Swipe to show code editor

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

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Секція 1. Розділ 5
Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt