File size: 1,027 Bytes
01dd930
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b017739
01dd930
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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