src/ei_mcoe/ei_mcoe.py
def add_source_cols(df):
    """Create column multindex to show data sources.

    Args:
        df (pandas.DataFrame): A finished dataframe in need of adding a
            multiindex for sources.

    Returns:
        pandas.DataFrame: A DataFrame with a multindex that references the
            source of each of the columns. Only column headers that appear in
            the name_clean_dict AND data_source_dict will be included in the
            output.
    """
    logger.info('Adding source cols')
    source_dict = {}
    # Make a new dictionary with only sources of columns relevant to this table
    for key, value in data_source_dict.items():
        if key in df.columns.to_list():
            logger.info(key)
            source_dict.update({key: value})
    # Swap columns and rows to map on sources
    df = df.T.reset_index()
    df['Source'] = df['index'].map(lambda x: data_source_dict[x][0])
    df['Description'] = df['index'].map(lambda x: data_source_dict[x][1])
    # Switch columns back to rows
    df = df.set_index(['Source', 'Description', 'index']).T
    return df
Create column multindex to show data sources.

    Args:
        df (pandas.DataFrame): A finished dataframe in need of adding a
            multiindex for sources.

    Returns:
        pandas.DataFrame: A DataFrame with a multindex that references the
            source of each of the columns. Only column headers that appear in
            the name_clean_dict AND data_source_dict will be included in the
            output.
    
Create column multindex to show data sources.
Create column multindex to show data sources .
def add_source_cols(df):
    logger.info('Adding source cols')
    source_dict = {}
    for key, value in data_source_dict.items():
        if key in df.columns.to_list():
            logger.info(key)
            source_dict.update({key: value})
    df = df.T.reset_index()
    df['Source'] = df['index'].map(lambda x: data_source_dict[x][0])
    df['Description'] = df['index'].map(lambda x: data_source_dict[x][1])
    df = df.set_index(['Source', 'Description', 'index']).T
    return df
def add_source_cols ( df ) : logger . info ( 'Adding source cols' ) source_dict = { } for key , value in data_source_dict . items ( ) : if key in df . columns . to_list ( ) : logger . info ( key ) source_dict . update ( { key : value } ) df = df . T . reset_index ( ) df [ 'Source' ] = df [ 'index' ] . map ( lambda x : data_source_dict [ x ] [ 0 ] ) df [ 'Description' ] = df [ 'index' ] . map ( lambda x : data_source_dict [ x ] [ 1 ] ) df = df . set_index ( [ 'Source' , 'Description' , 'index' ] ) . T return df
Create column multindex to show data sources.
Create column multindex to show data sources .
"""Create column multindex to show data sources.

    Args:
        df (pandas.DataFrame): A finished dataframe in need of adding a
            multiindex for sources.

    Returns:
        pandas.DataFrame: A DataFrame with a multindex that references the
            source of each of the columns. Only column headers that appear in
            the name_clean_dict AND data_source_dict will be included in the
            output.
    """ # Make a new dictionary with only sources of columns relevant to this table # Swap columns and rows to map on sources # Switch columns back to rows
A DataFrame with a multindex that references the
source of each of the columns. Only column headers that appear in
the name_clean_dict AND data_source_dict will be included in the
output.
A DataFrame with a multindex that references the source of each of the columns . Only column headers that appear in the name_clean_dict AND data_source_dict will be included in the output .
pandas.DataFrame
df
A finished dataframe in need of adding a
multiindex for sources.
A finished dataframe in need of adding a multiindex for sources .