-1

Wrote a code

df=data.copy()
for column in data.columns:
    Q1= np.quantile(data[column],0.25)
    Q3= np.quantile(data[column],0.75)
    IQR = Q3-Q1
    Low = Q1 - 3*(IQR)
    High = Q3 + 3*(IQR)
    df = df[(df[column] > Low ) | (df[column] < High)][column]

How to write the code so that it only accepts what's in the range. The code is showing an error.

----> 9     df = df[(df[column] > Low ) | (df[column] < High)][column]
desertnaut
  • 57,590
  • 26
  • 140
  • 166

1 Answers1

0

Yes, my logic was wrong. This one worked.

df=data.copy()
for column in data.columns:
    Q1= np.quantile(data[column],0.25)
    Q3= np.quantile(data[column],0.75)
    IQR = Q3-Q1
    Low = Q1 - 3*(IQR)
    High = Q3 + 3*(IQR)
    df = df[df[column].between(Low, High)]