Зміст курсу
Advanced Techniques in pandas
Advanced Techniques in pandas
Managing an Incorrect Column
So, you received the result object
. This means that the type of the column is non-numerical, but to calculate necessary values, the column need to be numerical. Let's change that.
- Firstly, we need to replace
-
with.
. To do so, you will apply the method.str.replace()
to replace the character in the string in the dataset column. The syntax isdata['column_name'].str.replace('old_symbol','new_symbol')
In our case,old_symbol
is-
, and.
is thenew_symbol
; - Then, convert the column to the float
data
type. To do so, use.astype()
method. The syntax isdata['column_name'].astype('type')
.
In our case, the type is'float'
.
Swipe to show code editor
Your task is to:
- Follow the algorithm above and firstly replace
-
with.
in the column'Fare'
. - Convert the column
'Fare'
to the'float'
data type. - Output the type of the column
'Fare'
.
Дякуємо за ваш відгук!
Managing an Incorrect Column
So, you received the result object
. This means that the type of the column is non-numerical, but to calculate necessary values, the column need to be numerical. Let's change that.
- Firstly, we need to replace
-
with.
. To do so, you will apply the method.str.replace()
to replace the character in the string in the dataset column. The syntax isdata['column_name'].str.replace('old_symbol','new_symbol')
In our case,old_symbol
is-
, and.
is thenew_symbol
; - Then, convert the column to the float
data
type. To do so, use.astype()
method. The syntax isdata['column_name'].astype('type')
.
In our case, the type is'float'
.
Swipe to show code editor
Your task is to:
- Follow the algorithm above and firstly replace
-
with.
in the column'Fare'
. - Convert the column
'Fare'
to the'float'
data type. - Output the type of the column
'Fare'
.
Дякуємо за ваш відгук!
Managing an Incorrect Column
So, you received the result object
. This means that the type of the column is non-numerical, but to calculate necessary values, the column need to be numerical. Let's change that.
- Firstly, we need to replace
-
with.
. To do so, you will apply the method.str.replace()
to replace the character in the string in the dataset column. The syntax isdata['column_name'].str.replace('old_symbol','new_symbol')
In our case,old_symbol
is-
, and.
is thenew_symbol
; - Then, convert the column to the float
data
type. To do so, use.astype()
method. The syntax isdata['column_name'].astype('type')
.
In our case, the type is'float'
.
Swipe to show code editor
Your task is to:
- Follow the algorithm above and firstly replace
-
with.
in the column'Fare'
. - Convert the column
'Fare'
to the'float'
data type. - Output the type of the column
'Fare'
.
Дякуємо за ваш відгук!
So, you received the result object
. This means that the type of the column is non-numerical, but to calculate necessary values, the column need to be numerical. Let's change that.
- Firstly, we need to replace
-
with.
. To do so, you will apply the method.str.replace()
to replace the character in the string in the dataset column. The syntax isdata['column_name'].str.replace('old_symbol','new_symbol')
In our case,old_symbol
is-
, and.
is thenew_symbol
; - Then, convert the column to the float
data
type. To do so, use.astype()
method. The syntax isdata['column_name'].astype('type')
.
In our case, the type is'float'
.
Swipe to show code editor
Your task is to:
- Follow the algorithm above and firstly replace
-
with.
in the column'Fare'
. - Convert the column
'Fare'
to the'float'
data type. - Output the type of the column
'Fare'
.