Summarizing numerical data is an important part of data analysis, and there are many ways to do it in Python. Here are a few common techniques:
1. Mean: The mean is the average of all the values in the dataset. You can calculate the mean using NumPy's mean() function:
|
import numpy as np
data = [1, 2, 3, 4, 5]
mean = np.mean(data)
print(mean)
|
2. Median: The median is the middle value in the dataset when the values are sorted in order. You can calculate the median using NumPy's median() function:
|
import numpy as np
data = [1, 2, 3, 4, 5]
median = np.median(data)
print(median)
|
3. Mode: The mode is the value that appears most frequently in the dataset. You can calculate the mode using SciPy's mode() function:
|
from scipy import stats
data = [1, 2, 2, 3, 4, 4, 4, 5]
mode = stats.mode(data)
print(mode)
|
4. Range: The range is the difference between the largest and smallest values in the dataset. You can calculate the range using NumPy's ptp() function:
|
import numpy as np
data = [1, 2, 3, 4, 5]
range = np.ptp(data)
print(range)
|
These are just a few examples of how you can summarize numerical data in Python. There are many other techniques you can use, depending on the specific needs of your analysis.