📊 Still guessing averages? Learn executing basic stats in Python


Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python.

You have a spreadsheet with 500 numbers. Your boss asks: "What do you see?"

Most will freeze, scroll, guess. Not you!

3 Python functions to turn raw numbers into answers.​ No calculator, excel sheets. Just code.​

Statistics isn't boring math. It's how you make decisions with data.​

Using just the statistics module we find "center" of any dataset. Any data analyst must know the basics‼️

🎯 Compute simple average or mean

In:
import statistics

sales = [120, 340, 280, 150, 290, 310, 180]
average_sale = statistics.mean(sales)
print(average_sale)
Out: 238.57142857142858

📈 Median - Middle value when numbers are sorted

In:
prices = [45000, 48000, 52000, 55000, 150000]
middle = statistics.median(prices)
print(middle)
Out: 52000

🚩 Outlier spotting - mean vs median

Mean is influenced by outliers (anomaly or data error). Median is not. Stats like income, house prices are therefore reported as median

In:
normal_data = [100, 110, 105, 115, 120]
outlier_data = [100, 110, 105, 115, 10000]

print(statistics.mean(normal_data))
print(statistics.mean(outlier_data))
print(statistics.median(outlier_data))
Out:
110.0
2086.0
110

💡 Median for even number of items - Average of two middle values

In:
scores = [78, 85, 88, 92]
middle = statistics.median(scores)
print(middle)
Out: 86.5

🤝 Mode - Most common value

Example - common product ratings

In:
ratings = [5, 4, 5, 3, 4, 5, 4, 5, 5]
most_common = statistics.mode(ratings)
print(most_common)
Out: 5

🌄 Handle multiple modes

Example: Both 4 and 5 (product id) are equally popular among customers

In:
votes = [5, 4, 5, 3, 4, 5, 4]
all_modes = statistics.multimode(votes)
print(all_modes)
Out: [5, 4]

⭐📣 That's it for today! If you liked it, please share it with anyone who will find it useful and share your feedback below 🐼

Pandas Daily

Beginner to Expert in Python in just 5 minutes

Read more from Pandas Daily

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. Last week we introduced numpy. Created bunch of arrays, sliced them and did some math with them. To prepare data for machine learning or any analysis, we need to learn to control their shape. Today - Reshape flat lists into grids. Flatten 2D tables back to 1D arrays. Create arrays filled with zeros, ones, or random numbers. ⏪ Recap: See dimensions first In: import numpy as np sales = np.array([120, 340,...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. TGIF! Everyone is talking about AI. Most people take courses. You're going to build it instead. Let's create a simple sentiment analyzer that reads customer reviews and classifies them as positive or negative. No machine learning libraries—just Python. 🎯 Define list of positive and negative words In: positive_words = ["good", "great", "excellent", "amazing", "love", "best"] negative_words = ["bad",...

Welcome back to Pandas Daily! Your daily 5-minute boost to becoming confident in Python. We created arrays on Day 1. Sliced them on Day 2. Now comes the real computational power of NumPy. Doing math on entire datasets. No loops. No iteration. Just one line. Add monthly revenues across regions. Calculate profit margins. Find averages. All in seconds!! Let's dive in.. 🍃 Add/Subtract like a breeze In: import numpy as np jan_sales = np.array([120, 340, 210]) feb_sales = np.array([150, 290, 180])...