Home Handling Non-Numeric Data in Numeric Columns
Post
Cancel

Handling Non-Numeric Data in Numeric Columns

Converting Non-Numeric Data to Numeric

Conversion

Use pd.to_numeric function to convert the column to numeric vales

  • Non-Numeric Values: Non-numeric entries(e.g., dashes, empty strings) are automatically converted to NaN

Handling NaN Values

  1. Drop NaN Values:
    • Method: Use dropna() to remove rows where column contains NaN
    • Result: Rows with missing or invalid data are removed, leaving only valid numeric entries
  2. Fill NaN Values:
    • Method: Use fillna() to replace NaN with a default value (e.g., 0) or a statistical measure(e.g., the median)
This post is licensed under CC BY 4.0 by the author.