Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions examples/library_examples/pandas_matplotlib/README.md
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions examples/library_examples/pandas_matplotlib/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""

Check failure on line 1 in examples/library_examples/pandas_matplotlib/example.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (INP001)

examples/library_examples/pandas_matplotlib/example.py:1:1: INP001 File `examples/library_examples/pandas_matplotlib/example.py` is part of an implicit namespace package. Add an `__init__.py`.
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

Check failure on line 14 in examples/library_examples/pandas_matplotlib/example.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

examples/library_examples/pandas_matplotlib/example.py:13:1: I001 Import block is un-sorted or un-formatted

# 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)
Loading