Time Series Analysis
Time Series Analysis
Turn a stream of time-stamped events into a tidy monthly summary. Ciaren does this by extracting date parts and grouping by them.
You'll use: File Input → Change Types → Extract Date Parts → Group by + Aggregate → Rename → Sort → File Output.
Scope
Ciaren aggregates time data by calendar period (year, month, day, weekday,
hour). It does not do rolling windows or resample-style smoothing — for those,
export the Python and add a .rolling(...) step. See Next steps below.
Sample data
events.csv:
event_id,occurred_at,value
1,2024-01-05,10
2,2024-01-20,14
3,2024-02-02,9
4,2024-02-18,21
5,2024-03-01,17
6,2024-03-29,13
Upload it on the Datasets page (📥 download events.csv).
Build the flow
- File Input — File type CSV, select
events.csv. - Change Types —
casts: { "occurred_at": "datetime", "value": "float" }. - Extract Date Parts —
column: "occurred_at",parts: ["year", "month"]. This addsoccurred_at_yearandoccurred_at_monthcolumns. - Group by + Aggregate —
group_by: ["occurred_at_year", "occurred_at_month"],aggregations: { "value": "sum", "event_id": "count" }. - Rename Columns —
mapping: { "value": "total_value", "event_id": "num_events" }. - Sort Rows —
columns: ["occurred_at_year", "occurred_at_month"],ascending: true. - File Output —
format: csv(namemonthly_summary).
Exported Python
import pandas as pd
df_events = pd.read_csv('events.csv')
df_events = df_events.assign(occurred_at=lambda _d: pd.to_datetime(_d['occurred_at']), value=lambda _d: _d['value'].astype('float64'))
_dt = pd.to_datetime(df_events['occurred_at'])
df_events = df_events.assign(occurred_at_year=_dt.dt.year, occurred_at_month=_dt.dt.month)
df_events = (
df_events.groupby(['occurred_at_year', 'occurred_at_month'])
.agg({'value': 'sum', 'event_id': 'count'})
.reset_index()
.rename(columns={'value': 'total_value', 'event_id': 'num_events'})
.sort_values(['occurred_at_year', 'occurred_at_month'])
)
df_events.to_csv('monthly_summary.csv', index=False)
Result
The raw event-level rows are collapsed into monthly summaries. The date column is
split into year and month so each period becomes its own group key.
| event_id | occurred_at | value |
|---|---|---|
| 1 | 2024-01-05 | 10 |
| 2 | 2024-01-20 | 14 |
| 3 | 2024-02-02 | 9 |
| 4 | 2024-02-18 | 21 |
| 5 | 2024-03-01 | 17 |
| 6 | 2024-03-29 | 13 |
| occurred_at_yearnew | occurred_at_monthnew | total_valuenew | num_eventsnew |
|---|---|---|---|
| 2024 | 1 | 24 | 2 |
| 2024 | 2 | 30 | 2 |
| 2024 | 3 | 30 | 2 |
Next steps
- Smoothing / moving averages. Export the flow and add a rolling window to the
result, e.g.
df_events['rolling_avg'] = df_events['total_value'].rolling(3).mean(). - Day-of-week patterns. Add
weekdayto the Extract Date Parts node and group by it instead. - Data Quality Checks