|
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) |
|
|
|
df_band = df_band.drop_duplicates(subset=["ID"]) |
|
df_band = df_band[["code", "band"]] |
|
df_band = ( |
|
df_band.groupby("code")["band"] |
|
.apply(lambda x: "/".join(sorted(x))) |
|
.reset_index() |
|
) |
|
|
|
df_band.rename(columns={"band": "site_config_band"}, inplace=True) |
|
|
|
return df_band |
|
|