is more than or equal to lower_cutoff and less than or equal to upper_cutoff.
df = df[(df["age"] >= lower_cutoff) & (df["age"] <= upper_cutoff)]
We are plotting a box plot after the outlier trimming. The box plot now looks like the following:

As we can see from the above box plot, all outliers are trimmed.
And the output of the above program will be:
Lower cutoff of age: -6.6875
Upper cutoff of age: 64.8125
survived pclass sex age ... deck embark_town alive alone
33 0 2 male 66.0 ... NaN Southampton no True
54 0 1 male 65.0 ... B Cherbourg no False
96 0 1 male 71.0 ... A Cherbourg no True
116 0 3 male 70.5 ... NaN Queenstown no True
280 0 3 male 65.0 ... NaN Queenstown no True
456 0 1 male 65.0 ... E Southampton no True
493 0 1 male 71.0 ... NaN Cherbourg no True
630 1 1 male 80.0 ... A Southampton yes True
672 0 2 male 70.0 ... NaN Southampton no True
745 0 1 male 70.0 ... B Southampton no False
851 0 3 male 74.0 ... NaN Southampton no True
[11 rows x 15 columns]
survived pclass sex age ... deck embark_town alive alone
0 0 3 male 22.0 ... NaN Southampton no False
1 1 1 female 38.0 ... C Cherbourg yes False
2 1 3 female 26.0 ... NaN Southampton yes True
3 1 1 female 35.0 ... C Southampton yes False
4 0 3 male 35.0 ... NaN Southampton no True
[5 rows x 15 columns]








































0 Comments