From 3840d71afe2737910e14f036ca41e0b9ff367c07 Mon Sep 17 00:00:00 2001 From: studentpiyush Date: Tue, 14 Oct 2025 09:00:35 +0530 Subject: [PATCH 1/2] Add pandas+matplotlib example (examples/library_examples/pandas_matplotlib) --- .../pandas_matplotlib/README.md | 16 ++++++++ .../pandas_matplotlib/example.py | 40 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 examples/library_examples/pandas_matplotlib/README.md create mode 100644 examples/library_examples/pandas_matplotlib/example.py diff --git a/examples/library_examples/pandas_matplotlib/README.md b/examples/library_examples/pandas_matplotlib/README.md new file mode 100644 index 000000000000..02e165260d80 --- /dev/null +++ b/examples/library_examples/pandas_matplotlib/README.md @@ -0,0 +1,16 @@ +# Pandas + Matplotlib Example + +This example demonstrates a simple workflow using **pandas** and **matplotlib**: + +- Create a small dataset using pandas +- Perform a simple data transformation (moving average) +- Visualize the results with matplotlib (line chart) + +## Files + +- `example.py` — main script demonstrating the workflow + +## Requirements + +```bash +pip install pandas matplotlib diff --git a/examples/library_examples/pandas_matplotlib/example.py b/examples/library_examples/pandas_matplotlib/example.py new file mode 100644 index 000000000000..7ec29a0b3660 --- /dev/null +++ b/examples/library_examples/pandas_matplotlib/example.py @@ -0,0 +1,40 @@ +""" +Example: Using pandas and matplotlib together + +This script demonstrates how to: +1. Create a DataFrame using pandas +2. Perform a simple transformation +3. Visualize the results using matplotlib + +Requirements: + pip install pandas matplotlib +""" + +import pandas as pd +import matplotlib.pyplot as plt + +# Step 1: Create a sample DataFrame +data = { + "Month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"], + "Sales": [250, 300, 280, 350, 400, 380] +} +df = pd.DataFrame(data) + +# Step 2: Add a moving average column +df["Moving_Avg"] = df["Sales"].rolling(window=2).mean() + +# Step 3: Plot the data +plt.figure(figsize=(8, 5)) +plt.plot(df["Month"], df["Sales"], marker='o', label="Sales", color="blue") +plt.plot(df["Month"], df["Moving_Avg"], marker='s', label="Moving Avg", linestyle="--", color="orange") + +plt.title("Monthly Sales with Moving Average") +plt.xlabel("Month") +plt.ylabel("Sales") +plt.legend() +plt.grid(True, linestyle="--", alpha=0.6) +plt.tight_layout() +plt.show() + +# Optional: Print the DataFrame for reference +print(df) From 29210854d5f49a30166c7a01f627b721892c312c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 14 Oct 2025 04:20:24 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .../library_examples/pandas_matplotlib/example.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/library_examples/pandas_matplotlib/example.py b/examples/library_examples/pandas_matplotlib/example.py index 7ec29a0b3660..2d04a692378b 100644 --- a/examples/library_examples/pandas_matplotlib/example.py +++ b/examples/library_examples/pandas_matplotlib/example.py @@ -16,7 +16,7 @@ # Step 1: Create a sample DataFrame data = { "Month": ["Jan", "Feb", "Mar", "Apr", "May", "Jun"], - "Sales": [250, 300, 280, 350, 400, 380] + "Sales": [250, 300, 280, 350, 400, 380], } df = pd.DataFrame(data) @@ -25,8 +25,15 @@ # Step 3: Plot the data plt.figure(figsize=(8, 5)) -plt.plot(df["Month"], df["Sales"], marker='o', label="Sales", color="blue") -plt.plot(df["Month"], df["Moving_Avg"], marker='s', label="Moving Avg", linestyle="--", color="orange") +plt.plot(df["Month"], df["Sales"], marker="o", label="Sales", color="blue") +plt.plot( + df["Month"], + df["Moving_Avg"], + marker="s", + label="Moving Avg", + linestyle="--", + color="orange", +) plt.title("Monthly Sales with Moving Average") plt.xlabel("Month")