Retrieving boxplot data - Pandas

I need to get the statistics that were generated to draw a graph in Pandas (using the framework to create boxes). those. Quartile1, Quartile2, Quartile3, lower value of whiskers, upper value and emissions of whiskers. I tried the following query to draw a 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') 

Is there a way to do this instead of manually calculating the values?

+5
source share
1 answer

One option is to use the y data from the graphs - probably the most useful for emissions (pilots)

 _, 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"]] 

But it might be easier to get other values ​​(including IQR) with

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

or as suggested by WoodChopper

 stats = df.describe() 
+6
source

Source: https://habr.com/ru/post/1235177/


All Articles