n_dimensional_array_to_dataframe#
- caf.toolkit.pandas_utils.numpy_conversions.n_dimensional_array_to_dataframe(mat, dimension_cols, value_col, drop_zeros=False)[source]#
Convert an N-dimensional numpy array to a pandas.Dataframe.
- Parameters:
mat (ndarray) – The N-dimensional array to convert.
dimension_cols (dict[str, list[Any]]) – A dictionary of {col_name: col_values} pairs. dimension_cols.keys() MUST return a list of keys in the same order as the dimension that each col_name refers to. dimension_cols.keys() is defined by the order the keys are added to a dictionary. col_values MUST be in the same order as the values in the dimension they refer to.
value_col (str) – The name to give to the value columns in the output dataframe.
drop_zeros (bool) – Whether to drop any rows in the final dataframe where the value is 0. If False then a full product of all dimension_cols is returned as the index.
- Returns:
A pandas.Dataframe of mat with the attached index defined by dimension_cols.
- Return type:
dataframe
Examples
# TODO(BT): Add examples to this one. It’s a bit confusing in abstract!