[Python] How to Fix SettingWithCopyWarning When Modifying a Pandas DataFrame? [duplicate]

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with a Pandas DataFrame and trying to fill NaN values in a column, but I keep getting the following warning:

    C:\Users\USER\anaconda3\envs\learn-env\lib\site-packages\pandas\core\series.py:4517: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    return super().fillna(


    df["Total.Fatal.Injuries"].fillna(0, inplace=True)
    df["Total.Serious.Injuries"].fillna(0, inplace=True)

    Continue reading...

Compartilhe esta Página