Written by: Marlon Colca
Posted on 26 May 2025 - 4 months ago
python pandas analytics
In this post, we’ll learn how to create quick and effective visualizations using Pandas (which uses Matplotlib under the hood)
Data exploration isn’t complete without visualizations.
Numbers and tables are useful, but charts make trends and outliers immediately visible.
In this post, we’ll learn how to create quick and effective visualizations using Pandas (which uses Matplotlib under the hood).
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("prices_with_missing_data.csv")
# Fill missing values for smoother plots
df['quantity_sold'] = df['quantity_sold'].fillna(0)
df['price'] = df['price'].fillna(df['price'].mean())
df['brand'] = df['brand'].fillna("Unknown")
df['date'] = pd.to_datetime(df['date'])
Line plots are perfect for showing trends.
daily_sales = df.groupby("date")["quantity_sold"].sum()
daily_sales.plot(figsize=(10,5), title="Daily Quantity Sold", ylabel="Units")
plt.show()
Bar plots show comparisons between categories.
df["revenue"] = df["price"] * df["quantity_sold"]
brand_revenue = df.groupby("brand")["revenue"].sum()
brand_revenue.plot(kind="bar", figsize=(8,5), title="Total Revenue by Brand")
plt.ylabel("Revenue")
plt.show()
Histograms help identify the distribution of numeric values.
df["price"].plot(kind="hist", bins=10, edgecolor="black", figsize=(8,5), title="Price Distribution")
plt.xlabel("Price")
plt.show()
Scatter plots reveal relationships between variables.
df.plot(kind="scatter", x="price", y="quantity_sold", figsize=(8,5), title="Price vs Quantity Sold")
plt.show()
In this part, we learned how to:
Next up: Part 10 – Advanced Pandas Tips and Tricks
We’ll explore .apply()
, .map()
, .query()
, and other powerful tools to write cleaner, faster Pandas code.
Now it’s time to explore advanced Pandas techniques that will make your code more efficient, expressive, and Pythonic.
29 May 2025 - 4 months ago