python/datasources/cdc_restricted_local.py
def accumulate_data(df, groupby_cols, overall_df, demographic_col,
                    names_mapping):
    """Converts/adds columns for cases, hospitalizations, deaths. Does some
    basic standardization of dataframe elements. Groups by given groupby_cols
    and aggregates. Returns sum of the aggregated df & overall_df.

    df: Pandas dataframe that contains a chunk of all of the raw data.
    groupby_cols: List of columns we want to groupby / aggregate on.
    overall_df: Pandas dataframe to add our aggregated data to.
    demographic_col: Name of the demographic column to standardize.
    names_mapping: Mapping from demographic value to standardized form.
    """
    # Add a columns of all ones, for counting the # of cases / records.
    df[std_col.COVID_CASES] = np.ones(df.shape[0], dtype=int)

    # Add columns for hospitalization yes/no/unknown and death yes/no/unknown,
    # as we aggregate and count these individually. Do a sanity check that we
    # covered all the data and drop the original hospitalization/death columns.
    df[std_col.COVID_HOSP_Y] = (df['hosp_yn'] == 'Yes')
    df[std_col.COVID_HOSP_N] = (df['hosp_yn'] == 'No')
    df[std_col.COVID_HOSP_UNKNOWN] = ((df['hosp_yn'] == 'Unknown') |
                                      (df['hosp_yn'] == 'Missing') |
                                      (df['hosp_yn'] == 'OTH'))
    df[std_col.COVID_DEATH_Y] = (df['death_yn'] == 'Yes')
    df[std_col.COVID_DEATH_N] = (df['death_yn'] == 'No')
    df[std_col.COVID_DEATH_UNKNOWN] = ((df['death_yn'] == 'Unknown') |
                                       (df['death_yn'] == 'Missing'))

    check_hosp = (df[std_col.COVID_HOSP_Y] | df[std_col.COVID_HOSP_N] |
                  df[std_col.COVID_HOSP_UNKNOWN]).all()
    check_deaths = (df[std_col.COVID_DEATH_Y] | df[std_col.COVID_DEATH_N] |
                    df[std_col.COVID_DEATH_UNKNOWN]).all()

    assert check_hosp, "All possible hosp_yn values are not accounted for"
    assert check_deaths, "All possible death_yn values are not accounted for"

    df = df.drop(columns=['hosp_yn', 'death_yn'])

    # Standardize the values in demographic_col using names_mapping.
    df = df.replace({demographic_col: names_mapping})

    # Group by the desired columns and compute the sum/counts of
    # cases/hospitalizations/deaths. Add this df to overall_df.
    df = df.groupby(groupby_cols).sum().reset_index()
    df = df.set_index(groupby_cols)
    if not overall_df.empty:
        return overall_df.add(df, fill_value=0)
    return df
Converts/adds columns for cases, hospitalizations, deaths. Does some
    basic standardization of dataframe elements. Groups by given groupby_cols
    and aggregates. Returns sum of the aggregated df & overall_df.

    df: Pandas dataframe that contains a chunk of all of the raw data.
    groupby_cols: List of columns we want to groupby / aggregate on.
    overall_df: Pandas dataframe to add our aggregated data to.
    demographic_col: Name of the demographic column to standardize.
    names_mapping: Mapping from demographic value to standardized form.
    
Converts/adds columns for cases, hospitalizations, deaths. Does some
basic standardization of dataframe elements. Groups by given groupby_cols
and aggregates. Returns sum of the aggregated df & overall_df.

Pandas dataframe that contains a chunk of all of the raw data.
groupby_cols: List of columns we want to groupby / aggregate on.
overall_df: Pandas dataframe to add our aggregated data to.
demographic_col: Name of the demographic column to standardize.
names_mapping: Mapping from demographic value to standardized form.
Converts / adds columns for cases hospitalizations deaths . Does some basic standardization of dataframe elements . Groups by given groupby_cols and aggregates . Returns sum of the aggregated df & overall_df . Pandas dataframe that contains a chunk of all of the raw data . groupby_cols : List of columns we want to groupby / aggregate on . overall_df : Pandas dataframe to add our aggregated data to . demographic_col : Name of the demographic column to standardize . names_mapping : Mapping from demographic value to standardized form .
def accumulate_data(df, groupby_cols, overall_df, demographic_col,
                    names_mapping):
    df[std_col.COVID_CASES] = np.ones(df.shape[0], dtype=int)
    df[std_col.COVID_HOSP_Y] = (df['hosp_yn'] == 'Yes')
    df[std_col.COVID_HOSP_N] = (df['hosp_yn'] == 'No')
    df[std_col.COVID_HOSP_UNKNOWN] = ((df['hosp_yn'] == 'Unknown') |
                                      (df['hosp_yn'] == 'Missing') |
                                      (df['hosp_yn'] == 'OTH'))
    df[std_col.COVID_DEATH_Y] = (df['death_yn'] == 'Yes')
    df[std_col.COVID_DEATH_N] = (df['death_yn'] == 'No')
    df[std_col.COVID_DEATH_UNKNOWN] = ((df['death_yn'] == 'Unknown') |
                                       (df['death_yn'] == 'Missing'))
    check_hosp = (df[std_col.COVID_HOSP_Y] | df[std_col.COVID_HOSP_N] |
                  df[std_col.COVID_HOSP_UNKNOWN]).all()
    check_deaths = (df[std_col.COVID_DEATH_Y] | df[std_col.COVID_DEATH_N] |
                    df[std_col.COVID_DEATH_UNKNOWN]).all()
    assert check_hosp, "All possible hosp_yn values are not accounted for"
    assert check_deaths, "All possible death_yn values are not accounted for"
    df = df.drop(columns=['hosp_yn', 'death_yn'])
    df = df.replace({demographic_col: names_mapping})
    df = df.groupby(groupby_cols).sum().reset_index()
    df = df.set_index(groupby_cols)
    if not overall_df.empty:
        return overall_df.add(df, fill_value=0)
    return df
def accumulate_data ( df , groupby_cols , overall_df , demographic_col , names_mapping ) : df [ std_col . COVID_CASES ] = np . ones ( df . shape [ 0 ] , dtype = int ) df [ std_col . COVID_HOSP_Y ] = ( df [ 'hosp_yn' ] == 'Yes' ) df [ std_col . COVID_HOSP_N ] = ( df [ 'hosp_yn' ] == 'No' ) df [ std_col . COVID_HOSP_UNKNOWN ] = ( ( df [ 'hosp_yn' ] == 'Unknown' ) | ( df [ 'hosp_yn' ] == 'Missing' ) | ( df [ 'hosp_yn' ] == 'OTH' ) ) df [ std_col . COVID_DEATH_Y ] = ( df [ 'death_yn' ] == 'Yes' ) df [ std_col . COVID_DEATH_N ] = ( df [ 'death_yn' ] == 'No' ) df [ std_col . COVID_DEATH_UNKNOWN ] = ( ( df [ 'death_yn' ] == 'Unknown' ) | ( df [ 'death_yn' ] == 'Missing' ) ) check_hosp = ( df [ std_col . COVID_HOSP_Y ] | df [ std_col . COVID_HOSP_N ] | df [ std_col . COVID_HOSP_UNKNOWN ] ) . all ( ) check_deaths = ( df [ std_col . COVID_DEATH_Y ] | df [ std_col . COVID_DEATH_N ] | df [ std_col . COVID_DEATH_UNKNOWN ] ) . all ( ) assert check_hosp , "All possible hosp_yn values are not accounted for" assert check_deaths , "All possible death_yn values are not accounted for" df = df . drop ( columns = [ 'hosp_yn' , 'death_yn' ] ) df = df . replace ( { demographic_col : names_mapping } ) df = df . groupby ( groupby_cols ) . sum ( ) . reset_index ( ) df = df . set_index ( groupby_cols ) if not overall_df . empty : return overall_df . add ( df , fill_value = 0 ) return df
Converts/adds columns for cases, hospitalizations, deaths.
Converts / adds columns for cases hospitalizations deaths .
"""Converts/adds columns for cases, hospitalizations, deaths. Does some
    basic standardization of dataframe elements. Groups by given groupby_cols
    and aggregates. Returns sum of the aggregated df & overall_df.

    df: Pandas dataframe that contains a chunk of all of the raw data.
    groupby_cols: List of columns we want to groupby / aggregate on.
    overall_df: Pandas dataframe to add our aggregated data to.
    demographic_col: Name of the demographic column to standardize.
    names_mapping: Mapping from demographic value to standardized form.
    """ # Add a columns of all ones, for counting the # of cases / records. # Add columns for hospitalization yes/no/unknown and death yes/no/unknown, # as we aggregate and count these individually. Do a sanity check that we # covered all the data and drop the original hospitalization/death columns. # Standardize the values in demographic_col using names_mapping. # Group by the desired columns and compute the sum/counts of # cases/hospitalizations/deaths. Add this df to overall_df.
df
groupby_cols
overall_df
demographic_col
names_mapping