diive.transform_yearmonth_matrix_to_longform¶
- diive.transform_yearmonth_matrix_to_longform(matrixdf, z_var_name='VALUE')[source]¶
Transform a year-month matrix into a long-form pandas Series with a datetime index.
Matrix Structure:
The input matrixdf must have:
Years as the index.
Months as the columns.
Numerical values representing the data.
Example
MONTH 1 2 3 YEAR 1997 2.0 9.0 5.0 1998 10.0 1.0 19.0 1999 8.0 22.0 13.0
Transformation:
The function combines the year (from the index) and month (from the columns) to create a datetime index. The corresponding values from the matrix become the values of the resulting Series.
Example Output (with z_var_name as ‘VALUE’):
VALUE TIMESTAMP 1997-01-01 2.0 1997-02-01 9.0 1997-03-01 5.0 ...
- Parameters:
- Return type:
- Returns:
pandas Series with a datetime index (‘YYYY-MM-01’ format, monthly start frequency ‘MS’) and values from the input matrix. The index is gap-free, covering every month from January of the first year to December of the last year. Months not present in the matrix (e.g. a seasonal record covering June-August only) are returned as NaN.