peakweather.utils

df_add_missing_columns(df: DataFrame, col0=None, col1=None) DataFrame

Add missing columns to a MultiIndex DataFrame with NaN values.

Parameters:
  • df (pd.DataFrame) – The input DataFrame.

  • col0 (list, optional) – The first level of the MultiIndex columns. If None, will use the existing columns.

  • col1 (list, optional) – The second level of the MultiIndex columns. If None, will use the existing columns.

Returns:

The DataFrame with missing columns added.

Return type:

pd.DataFrame

sliding_window_view(data: ndarray, window_size: int) ndarray

Creates a sliding window view of the input data.

Parameters:
  • data (np.ndarray) – The input data with shape (num_time_steps, num_stations, num_channels).

  • window_size (int) – The size of the sliding window.

Returns:

The sliding window view of the input data with shape

(num_windows, window_size, num_stations, num_channels).

Return type:

np.ndarray

to_pandas_freq(freq: str)

Convert a frequency string to a pandas frequency object.

Parameters:

freq (str) – The frequency string.

Returns:

The pandas frequency object.

Return type:

pd.DateOffset

Raises:

ValueError – If the frequency string is not valid.