Contenido del Curso
Data Manipulation using pandas
Data Manipulation using pandas
2. Preprocessing Data: Part II
Filling NA values
As you remember, removing all the rows with NA values is not always the best solution. Let's learn another method, how to fill NA values in a dataframe.
If you want to fill NAs with specific values, use the .fillna()
method. There are many options on what parameters you should use. Let's consider obligatory and the most appropriate ones:
value
- defines value that should be set instead of NAs. Can be a dictionary in format{'column_name': value_to_replace}
.method
- defines the method that should be used to fill NA values (for instance,'ffill'
: propagate last valid observation forward to next valid backfill /'bfill'
: use next valid observation to fill gap.limit
- number of consequtive NA values that should be filled. By default, this parameter isn't specified. For instance, we can fill the NA values within the'omphtotinch', 'hmwkswk'
columns with respective means.
¿Todo estuvo claro?