Python for Data Analysis (Preview)
Preview Python's data analysis ecosystem — pandas, numpy, matplotlib. See how Python is used for data science and analytics.
15 min•By Priygop Team•Updated 2026
Data Analysis Preview
Data Analysis Preview
# Data analysis without external libraries
# (Previewing what pandas/numpy do)
# Sample dataset
sales_data = [
{"month": "Jan", "revenue": 12000, "expenses": 8000},
{"month": "Feb", "revenue": 15000, "expenses": 9000},
{"month": "Mar", "revenue": 18000, "expenses": 10000},
{"month": "Apr", "revenue": 14000, "expenses": 8500},
{"month": "May", "revenue": 20000, "expenses": 11000},
{"month": "Jun", "revenue": 22000, "expenses": 12000},
]
# Analysis functions
def analyze_column(data, key):
values = [row[key] for row in data]
return {
"mean": sum(values) / len(values),
"min": min(values),
"max": max(values),
"sum": sum(values),
}
# Revenue analysis
print("=== Revenue Analysis ===")
rev_stats = analyze_column(sales_data, "revenue")
for stat, val in rev_stats.items():
print(f" {stat}: ${val:,.0f}")
# Profit calculation
print("\n=== Profit by Month ===")
for row in sales_data:
profit = row["revenue"] - row["expenses"]
margin = profit / row["revenue"] * 100
bar = "█" * int(margin / 5)
print(f" {row['month']}: ${profit:>6,} ({margin:.0f}%) {bar}")
# Growth rate
print("\n=== Month-over-Month Growth ===")
for i in range(1, len(sales_data)):
prev = sales_data[i-1]["revenue"]
curr = sales_data[i]["revenue"]
growth = (curr - prev) / prev * 100
arrow = "📈" if growth > 0 else "📉"
print(f" {sales_data[i]['month']}: {growth:+.1f}% {arrow}")
# With pandas (the real way):
print("\n=== With pandas ===")
print("import pandas as pd")
print("df = pd.DataFrame(sales_data)")
print("print(df.describe())")
print("df['profit'] = df['revenue'] - df['expenses']")
print("df.plot(x='month', y='profit', kind='bar')")Tip
Tip
Start with pandas for data analysis. Use matplotlib for quick plots and seaborn for statistical visualization.
Diagram
Loading diagram…
Everything in Python is an object — use type() to check
Common Mistake
Warning
Loading massive datasets into memory at once. Use chunksize parameter in pandas or generators for large files.
Quick Quiz
Practice Task
Note
(1) Read a CSV with pandas. (2) Filter and aggregate data. (3) Create a bar chart with matplotlib.