df_split¶
-
hhpy.ds.
df_split
(df: pandas.core.frame.DataFrame, split_by: Union[List[str], str], return_type: str = 'dict', print_key: bool = False, sep: str = '_', key_sep: str = '==') → Union[list, dict][source]¶ Split a pandas DataFrame by column value and returns a list or dict
Parameters: - df – pandas DataFrame to be split
- split_by – Column(s) to split by, creates a sub-DataFrame for each level
- return_type – one of [‘list’, ‘dict’], if list returns a list of sub-DataFrame, if dict returns a dictionary with each level as keys
- print_key – whether to include the column names in the key labels
- sep – separator to use in the key labels between columns
- key_sep – separator to use in the key labels between key and value
Returns: see return_type