I'm new to pandas, I just want to drop some rows in a DataFrame inplace, but there are warnings:
/opt/conda/lib/python3.7/site-packages/pandas/core/frame.py:4315: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
the function that gives errors:
def single_drop(df: pd.DataFrame):
"""Drop rows with '-99' entries."""
reduced_df = df
for i in range(len(reduced_df)):
if reduced_df.loc[i].isin([-99]).any():
reduced_df.drop([i], inplace=True)
I don't think I have used chained assignment, or I have?
and I try to repalce the code to:
reduced_df = reduced_df.drop([i])
the error is gone.