FutureWarning: Automatic reindexing on DataFrame vs Series comparisons is deprecated and will raise ValueError in a future version

Viewed 1824

/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:8: FutureWarning: Automatic reindexing on DataFrame vs Series comparisons is deprecated and will raise ValueError in a future version. Do left, right = left.align(right, axis=1, copy=False) before e.g. left == right

I tried to remove outlier from my data frame using z-score manually by me

numerical_cols=df.select_dtypes(['int64','float64'])
for col in numerical_cols:
    feature_value_less_than_3sigma=df[col].mean()-3*(df[col].std())
    feature_value_greater_than_3sigma=df[col].mean()+3*(df[col].std())
    df = df[~((df[col] < (feature_value_less_than_3sigma)) |(df[col] > (feature_value_greater_than_3sigma)))]
else:
    print('\nAfter: ',df.shape)

I don't know what this error is telling and I like to know about it ,Can anyone explain with some simple example

2 Answers

Instead of:

df = df[~((df[col] < (feature_value_less_than_3sigma)) |(df[col] > (feature_value_greater_than_3sigma)))]

Use:

df = df.query('~(%s < @feature_value_less_than_3sigma or %s > @feature_value_greater_than_3sigma)' %(col,col))

This should remove the error.

Try this:

df = df[~((df[col].lt(feature_value_less_than_3sigma)) |(df[col].gt (feature_value_greater_than_3sigma)))]
Related