@gilbertoesp


4+
2
100%

01

02

03

04

analysis.py
import pandas as pd
import matplotlib.pyplot as plt

# Load & clean data
df = pd.read_csv('sales.csv',
         parse_dates=['date'])
df.dropna(subset=['revenue'],
         inplace=True)

# Monthly totals by segment
monthly = (
  df.groupby([
    pd.Grouper(key='date',
               freq='ME'),
    'segment'
  ])['revenue']
  .sum()
  .unstack(fill_value=0)
)

# Plot each segment
fig, ax = plt.subplots()
for seg in monthly.columns:
  ax.plot(
    monthly.index,
    monthly[seg],
    label=seg,
    linewidth=2
  )

ax.set_title('Revenue by Segment')
ax.legend()
ax.grid(alpha=0.3)
plt.tight_layout()
plt.savefig('output.png')

01

02

03

04

📍
Hermosillo, Sonora, México
💬
English & Español