columns_to_MultiIndex
- postprocessinglib.utilities._helper_functions.columns_to_MultiIndex(cols: Index) MultiIndex
Converts flat columns to MultiIndex by detecting new stations based on ‘QOMEAS’ patterns. Each new ‘QOMEAS’ indicates the start of a new station group. It is used to convert the column names and indexes to multiindexes that can be used to more easily select specific columns from the dataframe.
- Parameters:
cols (pd.Index) – the single level column index to be converted
- Returns:
the MultiIndex with two levels
- Return type:
pd.MultiIndex
Example
>>> import pandas as pd >>> from postprocessinglib.utilities import _helper_functions >>> index = pd.Index(["obs_st1", "sim_st1", "sim_st1", "sim_st1", "obs_st2", "sim_st2", "sim_st2", "sim_st2"]) >>> multi_index = _helper_functions.colums_to_MultiIndex(index) >>> print(multi_index) MultiIndex([('st1', 'OBS'), ('st1', 'SIM1'), ('st1', 'SIM2'), ('st1', 'SIM3'), ('st2', 'OBS'), ('st2', 'SIM1'), ('st2', 'SIM2'), ('st2', 'SIM3')], )