Created
July 19, 2024 12:00
-
-
Save dennisnderitu254/1585bf05c57f452fa031f5f06a3534d2 to your computer and use it in GitHub Desktop.
How to calculate Interquartile range in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Calculating Interquartile Range in python | |
| # Example data (ages of students) | |
| data = [20, 19, 21, 22, 18, 23, 20, 21, 22, 19] | |
| # Sort the data | |
| data.sort() | |
| # Calculate quartiles | |
| Q1 = data[int(len(data) / 4)] | |
| Q3 = data[int(3 * len(data) / 4)] | |
| # Calculate IQR | |
| IQR = Q3 - Q1 | |
| # Print result | |
| print("Interquartile Range (IQR) calculation:") | |
| print(f"Q1 (first quartile): {Q1}") | |
| print(f"Q3 (third quartile): {Q3}") | |
| print(f"IQR: {IQR}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment