src/04_visualization/census_vis_synthesis.py
def clean_visible_minority(mino, year):
        """
        This function cleans the visible minority census data
        Args:
            mino (pd.DataFrame): The dataframe for visible minority data
            year (int): census year

        Returns:
            mino: A cleaned pandas dataframe
        """

        if year == 2011:
            mino = mino[mino.Type == 'Total']
            van_total = mino.sum()
            van_total['LocalArea'] = 'City of Vancouver'
            van_total['Type'] = 'Total'
            mino = mino.append(van_total, ignore_index=True)

        cols = ['Arab', 'Black', 'Chinese',
                'Filipino', 'Japanese', 'Korean',
                'Latin American', 'West Asian', 'South Asian',
                'Southeast Asian']
        
        if year == 2016:
            mino['Caucasian'] = mino['Not a visible minority'] / (mino['Not a visible minority'] + mino['Total visible minority population'])
             # calculate percentages
            for c in cols:
                mino[c] = mino[c] / (mino['Not a visible minority'] + mino['Total visible minority population'])
        else:
            mino['Caucasian'] = mino['Not a visible minority'] / (mino['Total population'])
             # calculate percentages
            for c in cols:
                mino[c] = mino[c] / (mino['Total population'])

        mino = mino[['LocalArea', 'Caucasian', 'Arab', 'Black',
                     'Chinese', 'Filipino', 'Japanese', 'Korean',
                     'Latin American', 'West Asian', 'South Asian',
                     'Southeast Asian']]

        return mino

        This function cleans the visible minority census data
        Args:
            mino (pd.DataFrame): The dataframe for visible minority data
            year (int): census year

        Returns:
            mino: A cleaned pandas dataframe
        
This function cleans the visible minority census data
This function cleans the visible minority census data
def clean_visible_minority(mino, year):
        if year == 2011:
            mino = mino[mino.Type == 'Total']
            van_total = mino.sum()
            van_total['LocalArea'] = 'City of Vancouver'
            van_total['Type'] = 'Total'
            mino = mino.append(van_total, ignore_index=True)
        cols = ['Arab', 'Black', 'Chinese',
                'Filipino', 'Japanese', 'Korean',
                'Latin American', 'West Asian', 'South Asian',
                'Southeast Asian']
        if year == 2016:
            mino['Caucasian'] = mino['Not a visible minority'] / (mino['Not a visible minority'] + mino['Total visible minority population'])
            for c in cols:
                mino[c] = mino[c] / (mino['Not a visible minority'] + mino['Total visible minority population'])
        else:
            mino['Caucasian'] = mino['Not a visible minority'] / (mino['Total population'])
            for c in cols:
                mino[c] = mino[c] / (mino['Total population'])
        mino = mino[['LocalArea', 'Caucasian', 'Arab', 'Black',
                     'Chinese', 'Filipino', 'Japanese', 'Korean',
                     'Latin American', 'West Asian', 'South Asian',
                     'Southeast Asian']]
        return mino
def clean_visible_minority ( mino , year ) : if year == 2011 : mino = mino [ mino . Type == 'Total' ] van_total = mino . sum ( ) van_total [ 'LocalArea' ] = 'City of Vancouver' van_total [ 'Type' ] = 'Total' mino = mino . append ( van_total , ignore_index = True ) cols = [ 'Arab' , 'Black' , 'Chinese' , 'Filipino' , 'Japanese' , 'Korean' , 'Latin American' , 'West Asian' , 'South Asian' , 'Southeast Asian' ] if year == 2016 : mino [ 'Caucasian' ] = mino [ 'Not a visible minority' ] / ( mino [ 'Not a visible minority' ] + mino [ 'Total visible minority population' ] ) for c in cols : mino [ c ] = mino [ c ] / ( mino [ 'Not a visible minority' ] + mino [ 'Total visible minority population' ] ) else : mino [ 'Caucasian' ] = mino [ 'Not a visible minority' ] / ( mino [ 'Total population' ] ) for c in cols : mino [ c ] = mino [ c ] / ( mino [ 'Total population' ] ) mino = mino [ [ 'LocalArea' , 'Caucasian' , 'Arab' , 'Black' , 'Chinese' , 'Filipino' , 'Japanese' , 'Korean' , 'Latin American' , 'West Asian' , 'South Asian' , 'Southeast Asian' ] ] return mino
This function cleans the visible minority census data
This function cleans the visible minority census data
"""
        This function cleans the visible minority census data
        Args:
            mino (pd.DataFrame): The dataframe for visible minority data
            year (int): census year

        Returns:
            mino: A cleaned pandas dataframe
        """ # calculate percentages # calculate percentages
A cleaned pandas dataframe
A cleaned pandas dataframe
mino
mino
The dataframe for visible minority data
The dataframe for visible minority data
year
None