to_dict#
- caf.van.utilities.to_dict(df, key_col, val_col, name=None)[source]#
Transform a dataframe to a dictionary.
- Parameters:
df (pd.DataFrame) – Dataframe with columns to transform to dictionary
key_col (str) – Column name as string to use as keys in dictionary.
val_col (tuple(str, type) or str) – Tuple with (column name, data type) or column name as string to use as values in dictionary, e.g. (“Values”, float) or “Values”.
name (str, optional) – Name of dataframe to display in error message
- Raises:
ValueError – If the value column in the dataframe is not of the expected type.
- Returns:
Dictionary with keys corresponding to elements in key_col, and values corresponding to elements in val_col.
- Return type: