Created
January 1, 2023 11:04
-
-
Save marttp/7d412bbe986eb3d557f7e8296c048042 to your computer and use it in GitHub Desktop.
Statistic with 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
# define the data set | |
data = [1, 2, 2, 3, 3, 3, 4] | |
# calculate the mean | |
mean = sum(data) / len(data) | |
print("Mean:", mean) # Mean: 2.5714285714285716 | |
# calculate the median | |
data.sort() | |
if len(data) % 2 == 0: | |
median = (data[len(data) // 2] + data[len(data) // 2 - 1]) / 2 | |
else: | |
median = data[len(data) // 2] | |
print("Median:", median) # Median: 2.5 | |
# calculate the mode | |
mode = max(data, key=data.count) | |
print("Mode:", mode) # Mode: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment