Práce s chybějícími hodnotami (I)

Feature Engineering for Machine Learning in Python

Robert O'Callaghan

Director of Data Science, Ordergroove

Řádkové mazání

      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

Řádkové mazání v Pythonu

# Drop all rows with at least one missing values
df.dropna(how='any')
Feature Engineering for Machine Learning in Python

Řádkové mazání v Pythonu

# Drop rows with missing values in a specific column
df.dropna(subset=['VersionControl'])
Feature Engineering for Machine Learning in Python

Problémy s mazáním

  • Odstraňuje platná data
  • Závisí na náhodnosti
  • Snižuje množství informací
Feature Engineering for Machine Learning in Python

Nahrazení řetězci

# Replace missing values in a specific column
# with a given string
df['VersionControl'].fillna(
    value='None Given', inplace=True
)
Feature Engineering for Machine Learning in Python

Zaznamenání chybějících hodnot

# Record where the values are not missing
df['SalaryGiven'] = df['ConvertedSalary'].notnull()
# Drop a specific column
df.drop(columns=['ConvertedSalary'])
Feature Engineering for Machine Learning in Python

Čas na procvičení

Feature Engineering for Machine Learning in Python

Preparing Video For Download...