close

How to calculate 1st and 3rd quartiles?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to calculate 1st and 3rd quartiles in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to calculate 1st and 3rd quartiles?

  1. How to calculate 1st and 3rd quartiles?

    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

  2. calculate 1st and 3rd quartiles

    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

Method 1

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

Method 2

You can use np.percentile to calculate quartiles (including the median):

>>> np.percentile(df.time_diff, 25)  # Q1
0.48333300000000001

>>> np.percentile(df.time_diff, 50)  # median
0.5

>>> np.percentile(df.time_diff, 75)  # Q3
0.51666699999999999

Or all at once:

>>> np.percentile(df.time_diff, [25, 50, 75])
array([ 0.483333,  0.5     ,  0.516667])

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read