Untitled
unknown
plain_text
7 months ago
919 B
2
Indexable
Never
from collections import Counter # Grouped data data = {'2-4': [2, 3, 4, 5], '5-7': [5, 6, 7], '8-10': [8, 9, 10]} frequency = [len(item[1]) for item in data.items()] range_ = [item[0].split('-') for item in data.items()] lower_limit = [int(item[0]) for item in range_] upper_limit = [int(item[1]) for item in range_] mean = sum([(lower_limit[i] + upper_limit[i])/2 * f-requency[i] for i in range(len(frequency))]) / sum(frequency) frequency = [item for sublist in data.values() for item in sublist] if len(frequency) % 2 == 0: median1 = frequency[len(frequency)//2] median2 = frequency[len(frequency)//2 - 1] median = (median1 + median2)/2 else: median = frequency[len(frequency)//2] val = Counter(frequency) findMode = dict(val) mode = [i for i, v in findMode.items() if v == max(list(val.values()))] print("Mean: ", mean) print("Median: ", median) print("Mode: ", mode)
Leave a Comment