Course Content
Analyzing and Visualizing Real-World Data
Analyzing and Visualizing Real-World Data
2. Preprocessing Data: Part II
Replacing Characters
Just as we removed characters, there are also two ways to perform replacements: either by using the .str
accessor or by using a lambda
function. Since we are only performing the replacement for one column, let's use the first approach.
Task
- Replace the commas with dots in the
'CPI'
column. Follow these steps:- Select the
'CPI'
column; - Use the
.str
accessor; - Replace the
','
symbols with'.'
using the.replace()
method; - Convert the values to
float
type; - Assign the obtained result to the
'CPI'
column.
- Select the
- Display the first row of the
df
dataframe and data types of thedf
dataframe.
Task
- Replace the commas with dots in the
'CPI'
column. Follow these steps:- Select the
'CPI'
column; - Use the
.str
accessor; - Replace the
','
symbols with'.'
using the.replace()
method; - Convert the values to
float
type; - Assign the obtained result to the
'CPI'
column.
- Select the
- Display the first row of the
df
dataframe and data types of thedf
dataframe.
Everything was clear?
Replacing Characters
Just as we removed characters, there are also two ways to perform replacements: either by using the .str
accessor or by using a lambda
function. Since we are only performing the replacement for one column, let's use the first approach.
Task
- Replace the commas with dots in the
'CPI'
column. Follow these steps:- Select the
'CPI'
column; - Use the
.str
accessor; - Replace the
','
symbols with'.'
using the.replace()
method; - Convert the values to
float
type; - Assign the obtained result to the
'CPI'
column.
- Select the
- Display the first row of the
df
dataframe and data types of thedf
dataframe.
Task
- Replace the commas with dots in the
'CPI'
column. Follow these steps:- Select the
'CPI'
column; - Use the
.str
accessor; - Replace the
','
symbols with'.'
using the.replace()
method; - Convert the values to
float
type; - Assign the obtained result to the
'CPI'
column.
- Select the
- Display the first row of the
df
dataframe and data types of thedf
dataframe.
Everything was clear?
Replacing Characters
Just as we removed characters, there are also two ways to perform replacements: either by using the .str
accessor or by using a lambda
function. Since we are only performing the replacement for one column, let's use the first approach.
Task
- Replace the commas with dots in the
'CPI'
column. Follow these steps:- Select the
'CPI'
column; - Use the
.str
accessor; - Replace the
','
symbols with'.'
using the.replace()
method; - Convert the values to
float
type; - Assign the obtained result to the
'CPI'
column.
- Select the
- Display the first row of the
df
dataframe and data types of thedf
dataframe.
Task
- Replace the commas with dots in the
'CPI'
column. Follow these steps:- Select the
'CPI'
column; - Use the
.str
accessor; - Replace the
','
symbols with'.'
using the.replace()
method; - Convert the values to
float
type; - Assign the obtained result to the
'CPI'
column.
- Select the
- Display the first row of the
df
dataframe and data types of thedf
dataframe.
Everything was clear?
Just as we removed characters, there are also two ways to perform replacements: either by using the .str
accessor or by using a lambda
function. Since we are only performing the replacement for one column, let's use the first approach.
Task
- Replace the commas with dots in the
'CPI'
column. Follow these steps:- Select the
'CPI'
column; - Use the
.str
accessor; - Replace the
','
symbols with'.'
using the.replace()
method; - Convert the values to
float
type; - Assign the obtained result to the
'CPI'
column.
- Select the
- Display the first row of the
df
dataframe and data types of thedf
dataframe.