Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
65 views
in Artificial Intelligence (AI) by (124k points)
How can I calculate percentiles in Python?

Please log in or register to answer this question.

1 Answer

0 votes
by (124k points)

Python provides several libraries, such as NumPy and pandas, that offer functions to calculate percentiles. Here's an example using NumPy:

import numpy as np

data = np.array([10, 15, 20, 25, 30, 35, 40, 45, 50])

# Calculate the 25th percentile
percentile_25 = np.percentile(data, 25)
print("25th percentile:", percentile_25)

# Calculate the 50th percentile (median)
median = np.median(data)
print("Median:", median)

# Calculate the 75th percentile
percentile_75 = np.percentile(data, 75)
print("75th percentile:", percentile_75)
 

Output:

25th percentile: 20.0
Median: 30.0
75th percentile: 40.0
 

In this example, we create a NumPy array called data and then use the np.percentile() function to calculate the desired percentiles.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...