Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

I want to get the statistical data that was produced to draw a box plot in Pandas(using data frame to make boxplots). for example Quartile1, Quartile2, Quartile3, lower whisker esteem, upper whisker value, and exceptions. I attempted the accompanying inquiry to draw the boxplot. 

import pandas as pd

df = pd.DataFrame(np.random.rand(100, 5), columns=['A', 'B', 'C', 'D', 'E'])

pd.DataFrame.boxplot(df,return_type = 'both')

I just want to know a good way to calculate the value instead of manually?

1 Answer

0 votes
by (26.4k points)

One alternative is to utilize the y information from the plots - presumably generally valuable for the outliers (fliers) 

_, bp = pd.DataFrame.boxplot(df, return_type='both')

outliers = [flier.get_ydata() for flier in bp["fliers"]]

boxes = [box.get_ydata() for box in bp["boxes"]]

medians = [median.get_ydata() for median in bp["medians"]]

whiskers = [whiskers.get_ydata() for whiskers in bp["whiskers"]]

However, it's most likely more clear to get different qualities (counting IQR) utilizing all things considered

quantiles = df.quantile([0.01, 0.25, 0.5, 0.75, 0.99])

as WoodChopper recommmended:

stats = df.describe()

Interested to learn python in detail? Come and Join the python course.

Related questions

0 votes
1 answer
asked Oct 9, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 31, 2019 in Data Science by sourav (17.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...