Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate 1st and 3rd quartiles?

I have DataFrame:

    time_diff   avg_trips 0   0.450000    1.0 1   0.483333    1.0 2   0.500000    1.0 3   0.516667    1.0 4   0.533333    2.0 

I want to get 1st quartile, 3rd quartile and median for the column time_diff. To obtain median, I use np.median(df["time_diff"].values).

How can I calculate quartiles?

like image 833
Dinosaurius Avatar asked Aug 28 '17 19:08

Dinosaurius


People also ask

What are quartile 1 and 3?

First quartile: the lowest 25% of numbers. Second quartile: between 0% and 50% (up to the median) Third quartile: 0% to 75% Fourth quartile: the highest 25% of numbers.


1 Answers

By using pandas:

df.time_diff.quantile([0.25,0.5,0.75])   Out[793]:  0.25    0.483333 0.50    0.500000 0.75    0.516667 Name: time_diff, dtype: float64 
like image 81
BENY Avatar answered Sep 30 '22 20:09

BENY