Types Conversion
You can discover that data can be stored in the dataset in the wrong format or type. The most common cases are:
- storing integer or float values as string variables.
- storing date and time values as strings.
- storing values in a form that can be converted to a more suitable one.
Let's explore the dataset exercise
containing info about diet, pulse, time, and kind of different exercises. There is sample data:
unnamed | id | diet | pulse | time | kind |
---|---|---|---|---|---|
35 | 12 | low fat | 104 | 30 min | walking |
64 | 22 | low fat | 104 | 15 min | running |
10 | 4 | low fat | 82 | 15 min | rest |
18 | 7 | no fat | 87 | 1 min | rest |
48 | 17 | no fat | 103 | 1 min | walking |
It makes sense to modify the time
column data: all rows contain the duration in minutes, so info about time units (min, sec, ot hours) is useless. We're gonna remove the extra symbols and store only numerical values, which additionally will be converted to int
.
Swipe to start coding
Apply the type conversion to the time
column. Remove the last 4 symbols which are equal to min
and convert the rest to int
. Check the sample.
Solution
Merci pour vos commentaires !
single
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion
Résumer ce chapitre
Expliquer le code dans file
Expliquer pourquoi file ne résout pas la tâche
Awesome!
Completion rate improved to 5.56
Types Conversion
Glissez pour afficher le menu
You can discover that data can be stored in the dataset in the wrong format or type. The most common cases are:
- storing integer or float values as string variables.
- storing date and time values as strings.
- storing values in a form that can be converted to a more suitable one.
Let's explore the dataset exercise
containing info about diet, pulse, time, and kind of different exercises. There is sample data:
unnamed | id | diet | pulse | time | kind |
---|---|---|---|---|---|
35 | 12 | low fat | 104 | 30 min | walking |
64 | 22 | low fat | 104 | 15 min | running |
10 | 4 | low fat | 82 | 15 min | rest |
18 | 7 | no fat | 87 | 1 min | rest |
48 | 17 | no fat | 103 | 1 min | walking |
It makes sense to modify the time
column data: all rows contain the duration in minutes, so info about time units (min, sec, ot hours) is useless. We're gonna remove the extra symbols and store only numerical values, which additionally will be converted to int
.
Swipe to start coding
Apply the type conversion to the time
column. Remove the last 4 symbols which are equal to min
and convert the rest to int
. Check the sample.
Solution
Merci pour vos commentaires !
Awesome!
Completion rate improved to 5.56single