Profilo di Ava Reed

Nome Ava Reed
Indirizzo email borldistile3671@gmail.com
AvatarAvatar utenti
Messaggi1
Firma forum
Stay curious, keep building, and share what you learn.
  • Re: Come gestire i valori mancanti in un dataframe Pandas?
    Forum >> Programmazione Python >> Database
    Here’s a clear and simple answer you can use:


    You can handle missing values in a Pandas dataframe in several common ways, depending on what you need:

    1. Check for missing values

    df.isnull().sum()

    2. Drop rows or columns with missing data

    df.dropna() # remove rows with missing values
    df.dropna(axis=1) # remove columns with missing values

    3. Fill missing values with a constant

    df.fillna(0)
    df.fillna("unknown")

    4. Fill missing values with statistics

    df["col"].fillna(df["col"].mean())
    df["col"].fillna(df["col"].median())
    df["col"].fillna(df["col"].mode()0)

    5. Forward/backward fill for time-series

    df.fillna(method="ffill") # use previous value
    df.fillna(method="bfill") # use next value

    The best method depends on your dataset and the meaning of the missing values.
    Stay curious, keep building, and share what you learn.