Iterate
Generalize the iteration to support different data formats. Namely,
- 2d numpy array
- 1d numpy array (long format)
- pandas Series
- pandas DataFrame with various columns
This powers the calendar plot and is passed into the plot_calendar
function.
Examples:
Plot calendar based on 1d numpy array.
import numpy as np
from latent_calendar.plot import plot_calendar
from latent_calendar.plot.iterate import iterate_long_array
data = np.ones(7 * 24)
plot_calendar(
iterate_long_array(data),
)
Plot calendar based on 2d numpy array.
from latent_calendar.plot import plot_calendar
data = np.ones((7, 24))
plot_calendar(
iterate_matrix(data),
)
Plot calendar for every half hour instead of every hour. NOTE: This happens automatically!
from latent_calendar.plot import plot_calendar
data = np.ones((7, 24 * 2))
plot_calendar(
iterate_matrix(data),
)
CalendarData
dataclass
IterConfig
dataclass
Bases: DataFrameConfig
Small wrapper to hold the column mapping in DataFrame.
Source code in latent_calendar/plot/iterate.py
VocabIterConfig
dataclass
Bases: DataFrameConfig
Small wrapper to hold the column mapping in the DataFrame.
Source code in latent_calendar/plot/iterate.py
iterate_dataframe(df, config)
Iterate the calendar data in DataFrame form based on config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame with calendar data. |
required |
config
|
DataFrameConfig
|
Configuration to describe what columns to use. |
required |
Source code in latent_calendar/plot/iterate.py
iterate_matrix(calendar_data)
Iterates the calendar matrix of values.