Skip to content

eds_scikit.biology.cleaning.cohort

select_cohort

select_cohort(measurement: DataFrame, studied_pop: Union[DataFrame, List[int]]) -> DataFrame

Select the patient_ids

PARAMETER DESCRIPTION
measurement

Target DataFrame

TYPE: DataFrame

studied_pop

List of patient_ids to select

TYPE: Union[DataFrame, List[int]]

RETURNS DESCRIPTION
DataFrame

Filtered DataFrame with selected patients

Source code in eds_scikit/biology/cleaning/cohort.py
 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
34
35
36
def select_cohort(
    measurement: DataFrame,
    studied_pop: Union[DataFrame, List[int]],
) -> DataFrame:
    """Select the patient_ids

    Parameters
    ----------
    measurement : DataFrame
        Target DataFrame
    studied_pop : Union[DataFrame, List[int]]
        List of patient_ids to select

    Returns
    -------
    DataFrame
        Filtered DataFrame with selected patients
    """
    logger.info("Selecting cohort...")

    if isinstance(studied_pop, DataFrame.__args__):
        filtered_measures = measurement.merge(
            studied_pop,
            on="person_id",
        )
    else:
        filtered_measures = measurement[measurement.person_id.isin(studied_pop)]

    return filtered_measures
Back to top