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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With