import pandas as pd def config_band(df: pd.DataFrame) -> pd.DataFrame: """ Create a dataframe that contains the site configuration band for each site code. Parameters ---------- df : pd.DataFrame The dataframe containing the site information, with columns "code" and "band" Returns ------- pd.DataFrame The dataframe containing the site configuration band for each site code, with columns "code" and "site_config_band" """ df_band = df[["code", "band"]].copy() df_band["ID"] = df_band[["code", "band"]].astype(str).apply("_".join, axis=1) # remove duplicates ID df_band = df_band.drop_duplicates(subset=["ID"]) df_band = df_band[["code", "band"]] df_band["band"] = df_band["band"].fillna("empty") df_band = ( df_band.groupby("code")["band"] .apply(lambda x: "/".join(sorted(x))) .reset_index() ) # rename band to config df_band.rename(columns={"band": "site_config_band"}, inplace=True) return df_band