Ex02-Outlier
You are given bhp.csv which contains property prices in the city of banglore, India. You need to examine price_per_sqft column and do following,
(1) Remove outliers using IQR
(2) After removing outliers in step 1, you get a new dataframe.
(3) use zscore of 3 to remove outliers. This is quite similar to IQR and you will get exact same result
(4) for the data set height_weight.csv find the following
(i) Using IQR detect weight outliers and print them
(ii) Using IQR, detect height outliers and print them
DEVELOPED BY: Lavanya S
REFERENCE NO: 212221220030
import pandas as pd
import seaborn as sns
import numpy as np
from scipy import stats
df=pd.read_csv('bhp.csv')
print(df['price_per_sqft'])
sns.boxplot(x="price_per_sqft",data=df)
df.shape
q1=df['price_per_sqft'].quantile(0.25)
q3=df['price_per_sqft'].quantile(0.75)
iqr=q3-q1
print("FIRST QUANTILE=",q1,"\nSECOND QUANTILE=",q3)
low=q1-1.5*iqr
high=q3+1.5*iqr
df_filtered=df[((df['price_per_sqft']>=low)&(df['price_per_sqft']<=high))]
sns.boxplot(x="price_per_sqft",data=df_filtered)
from scipy import stats
import numpy as np
z=np.abs(stats.zscore(df['price_per_sqft']))
df_filtered=df_filtered[(z<3)]
sns.boxplot(x='price_per_sqft',data=df_filtered)
q1=df.quantile(0.25)
q3=df.quantile(0.75)
iqr=q3-q1
low=q1-1.5*iqr
high=q3+1.5*iqr
df_fil=df[((df<=high)&(df>=low))]
outliers=np.setdiff1d(df['weight'],df_fil['weight'])
print("THE OUTLIERS IN THE DATA SET WEIGHT:",outliers)
q1=df.quantile(0.25)
q3=df.quantile(0.75)
iqr=q3-q1
low=q1-1.5*iqr
high=q3+1.5*iqr
df_fil=df[((df<=high)&(df>=low))]
outliers=np.setdiff1d(df['height'],df_fil['height'])
print("THE OUTLIERS IN THE DATA SET height:",outliers)