Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Calculating Basic Statistics | Probability, Statistics, and Simulation
Python for Mathematics

bookCalculating Basic Statistics

メニューを表示するにはスワイプしてください

When you analyze data, understanding its basic statistical measures is essential. The mean, median, and mode are three fundamental statistics that help you summarize and describe the central tendency of a dataset. The mean is commonly called the average and gives you a sense of the overall level of the data. The median identifies the middle value, which can be especially useful when your data contains outliers or is skewed. The mode shows the most frequently occurring value in your dataset, which is important for understanding patterns and commonalities in your data.

123456789101112131415
numbers = [3, 7, 2, 9, 7, 10, 3, 8] # Calculate mean using sum and len mean = sum(numbers) / len(numbers) # Calculate median using sorted and index sorted_numbers = sorted(numbers) n = len(sorted_numbers) if n % 2 == 1: median = sorted_numbers[n // 2] else: median = (sorted_numbers[n // 2 - 1] + sorted_numbers[n // 2]) / 2 print("Mean:", mean) print("Median:", median)
copy

While the mean and median help describe the center of your data, the mode highlights the value that appears most often in your dataset. This can be especially useful when analyzing data where certain values repeat frequently, such as survey responses or test scores. Unlike the mean and median, a dataset can have more than one mode (if multiple values tie for the highest frequency), or no mode at all (if all values are unique).

123456789101112
numbers = [3, 7, 2, 9, 7, 10, 3, 8] # Count occurrences of each value counts = {} for num in numbers: counts[num] = counts.get(num, 0) + 1 # Find the value(s) with the highest count max_count = max(counts.values()) modes = [num for num, count in counts.items() if count == max_count] print("Mode(s):", modes)
copy

1. What is the difference between mean and median?

2. How can you find the mode of a list in Python?

3. Fill in the blank: The mean is calculated as the sum of values divided by the ____.

question mark

What is the difference between mean and median?

正しい答えを選んでください

question mark

How can you find the mode of a list in Python?

正しい答えを選んでください

question-icon

Fill in the blank: The mean is calculated as the sum of values divided by the ____.

sum(numbers) /
The code prints the mean value of the list.

クリックまたはドラッグ`n`ドロップして空欄を埋めてください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 3.  1

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 3.  1
some-alt