Lidando com valores ausentes (I)

Feature Engineering for Machine Learning in Python

Robert O'Callaghan

Director of Data Science, Ordergroove

Exclusão por linha

      SurveyDate      ConvertedSalary     Hobby ... \
0  2/28/18 20:20                  NaN       Yes ...
1  6/28/18 13:26              70841.0       Yes ...
2    6/6/18 3:37                  NaN        No ...
3    5/9/18 1:06              21426.0       Yes ...
4  4/12/18 22:41              41671.0       Yes ...
Feature Engineering for Machine Learning in Python

Exclusão por linha em Python

# Remover todas as linhas com pelo menos um valor ausente
df.dropna(how='any')
Feature Engineering for Machine Learning in Python

Exclusão por linha em Python

# Remover linhas com valores ausentes em uma coluna específica
df.dropna(subset=['VersionControl'])
Feature Engineering for Machine Learning in Python

Problemas da exclusão

  • Exclui pontos de dados válidos
  • Pressupõe aleatoriedade
  • Reduz informação
Feature Engineering for Machine Learning in Python

Substituindo por strings

# Substituir valores ausentes em uma coluna específica
# por uma string dada
df['VersionControl'].fillna(
    value='None Given', inplace=True
)
Feature Engineering for Machine Learning in Python

Registrando valores ausentes

# Registrar onde os valores não estão ausentes
df['SalaryGiven'] = df['ConvertedSalary'].notnull()
# Remover uma coluna específica
df.drop(columns=['ConvertedSalary'])
Feature Engineering for Machine Learning in Python

Hora da prática

Feature Engineering for Machine Learning in Python

Preparing Video For Download...