Source code for ppc_robot_lib.reporting.transformation.renaming

import pandas


[docs] def suffix_columns( table: pandas.DataFrame, suffix: str, except_cols: list[str] = None, inplace: bool = True ) -> pandas.DataFrame: """ Suffixes column names with the given ``suffix``. If a column name is listed in ``except_cols``, its name is kept as-is. If the ``inplace`` parameter is set to ``True`` (the default), it is **Example:** >>> from ppc_robot_lib.reporting.transformation import suffix_columns >>> suffix_columns(performance, '_yday', except_cols=['Id', 'CampaignName']) :param table: Input table. :param suffix: Suffix to add to column names. :param except_cols: List of collumn names that will not be suffixed. :return: Updated table. If ``inplace=True``, the same instance is returned. """ if except_cols is None: except_cols = set() rename = {} for column in table.columns: if column not in except_cols: rename[column] = column + suffix new_table = table.rename(columns=rename, inplace=inplace) if inplace: return table else: return new_table