Skip to content

Instantly share code, notes, and snippets.

@lesutton
Created October 2, 2022 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesutton/542c80e0d97b78c2dcf41d80546242a5 to your computer and use it in GitHub Desktop.
Save lesutton/542c80e0d97b78c2dcf41d80546242a5 to your computer and use it in GitHub Desktop.
Calculate Outliers
plt.boxplot(dataframe['Age'])
plt.title('Boxplot of Age with Outlier Details Below')
plt.ylabel('Age')
plt.show()
def get_outliers(df):
q1=df.quantile(0.25)
q3=df.quantile(0.75)
IQR=q3-q1
outliers = df[((df<(q1-1.5*IQR)) | (df>(q3+1.5*IQR)))]
return outliers
outliers = get_outliers(dataframe['Age'])
print("There are " + str(len(outliers)) + " Outliers. The maximum outlier value is " + str(outliers.max()) + " and the minimum outlier value is " + str(outliers.min()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment