in orbit/utils/general.py [0:0]
def regenerate_base_df(df, time_col, key_col, val_cols=[], fill_na=None):
"""Given a dataframe, key column, time column and value column, re-generate multiple time-series to cover full range
date-time with all the keys. This can be a useful utils for working multiple time-series.
Parameters
----------
df : pd.DataFrame
time_col : str
key_col : str
val_cols : List[str]; values column considered to be imputed
fill_na : Optional[float]; values to fill when there are missing values of the row
Returns
-------
"""
out = df.copy()
unique_time = out[time_col].unique()
unique_key = out[key_col].unique()
new_df_base = expand_grid(
{
key_col: unique_key,
time_col: unique_time,
}
)
out = new_df_base.merge(out, how="left", on=[time_col, key_col])
if not isinstance(val_cols, list):
val_cols = list(val_cols)
out = out[[time_col, key_col] + val_cols]
if fill_na is not None:
out[val_cols] = out[val_cols].fillna(fill_na)
return out