Skip to content

Instantly share code, notes, and snippets.

@manmohan24nov
Last active October 1, 2020 15:54
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 manmohan24nov/236e1d855335aafc56bec0a64cf0c27c to your computer and use it in GitHub Desktop.
Save manmohan24nov/236e1d855335aafc56bec0a64cf0c27c to your computer and use it in GitHub Desktop.
# prtint min, max, median, first quartile, third quartile and random quartile
# using .quartile()
for i in num_col:
print(f'Min: {train[i].quantile(0)} First Quartile: {train[i].quantile(0.25)}'
f'Median: {train[i].quantile(0.5)} Third Quartile: {train[i].quantile(0.75)}'
f'Max: {train[i].quantile(0)} Random Quartile(90%): {train[i].quantile(0.9)}')
# quartile for categorical variables
def percentile(n):
def percentile_(x):
return np.percentile(x, n)
percentile_.__name__ = 'percentile_%s' % n
return percentile_
print(train[['Item_MRP',
'Outlet_Type']].groupby(['Outlet_Type']).agg({'Item_MRP':['min','max', percentile(25)]}))
# Here is code to create a box plot for the Item_MRP column.
train.boxplot(column="Item_MRP",
return_type='axes',
figsize=(8,8))
plt.text(x=0.74, y=185.64, s="3rd Quartile")
plt.text(x=0.8, y=140.99, s="Median")
plt.text(x=0.75, y=93.82, s="1st Quartile")
plt.text(x=0.9, y=31.29, s="Min")
plt.text(x=0.9, y=266.88, s="Max")
plt.text(x=0.6, y=140, s="IQR", rotation=90, size=40)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment