src/04_visualization/census_vis_synthesis.py
def clean_immigration_age(img_age, year):
        """
        This function cleans the immigration age census data
        Args:
            img_age (pd.DataFrame): The dataframe for immigration age data
            year (int): census year

        Returns:
            img_age: A cleaned pandas dataframe
        """

        img_age.rename(
            columns={'Under 5 years': 'Immigrants under 5 years',
                     '5 to 14 years': 'Immigrants 5 to 14 years',
                     '15 to 24 years': 'Immigrants 15 to 24 years',
                     '25 to 44 years': 'Immigrants 25 to 44 years',
                     '45 years and over': 'Immigrants 45 years and over'},
            inplace=True)

        img_age.drop(columns=['Unnamed: 0'], inplace=True)

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

        col_lis = list(img_age.columns)[2:]
        for col in col_lis:
            img_age[col] = img_age[col]/img_age['Total immigrant population']

        return img_age

        This function cleans the immigration age census data
        Args:
            img_age (pd.DataFrame): The dataframe for immigration age data
            year (int): census year

        Returns:
            img_age: A cleaned pandas dataframe
        
This function cleans the immigration age census data
This function cleans the immigration age census data
def clean_immigration_age(img_age, year):
        img_age.rename(
            columns={'Under 5 years': 'Immigrants under 5 years',
                     '5 to 14 years': 'Immigrants 5 to 14 years',
                     '15 to 24 years': 'Immigrants 15 to 24 years',
                     '25 to 44 years': 'Immigrants 25 to 44 years',
                     '45 years and over': 'Immigrants 45 years and over'},
            inplace=True)
        img_age.drop(columns=['Unnamed: 0'], inplace=True)
        if year == 2011:
            img_age = img_age[img_age['Type'] == 'Total']
            van_total = img_age.sum()
            van_total['LocalArea'] = 'City of Vancouver'
            van_total['Type'] = 'Total'
            img_age = img_age.append(van_total, ignore_index=True)
            img_age.drop(columns=['Type'], inplace=True)
        col_lis = list(img_age.columns)[2:]
        for col in col_lis:
            img_age[col] = img_age[col]/img_age['Total immigrant population']
        return img_age
def clean_immigration_age ( img_age , year ) : img_age . rename ( columns = { 'Under 5 years' : 'Immigrants under 5 years' , '5 to 14 years' : 'Immigrants 5 to 14 years' , '15 to 24 years' : 'Immigrants 15 to 24 years' , '25 to 44 years' : 'Immigrants 25 to 44 years' , '45 years and over' : 'Immigrants 45 years and over' } , inplace = True ) img_age . drop ( columns = [ 'Unnamed: 0' ] , inplace = True ) if year == 2011 : img_age = img_age [ img_age [ 'Type' ] == 'Total' ] van_total = img_age . sum ( ) van_total [ 'LocalArea' ] = 'City of Vancouver' van_total [ 'Type' ] = 'Total' img_age = img_age . append ( van_total , ignore_index = True ) img_age . drop ( columns = [ 'Type' ] , inplace = True ) col_lis = list ( img_age . columns ) [ 2 : ] for col in col_lis : img_age [ col ] = img_age [ col ] / img_age [ 'Total immigrant population' ] return img_age
This function cleans the immigration age census data
This function cleans the immigration age census data
"""
        This function cleans the immigration age census data
        Args:
            img_age (pd.DataFrame): The dataframe for immigration age data
            year (int): census year

        Returns:
            img_age: A cleaned pandas dataframe
        """
A cleaned pandas dataframe
A cleaned pandas dataframe
img_age
img_age
The dataframe for immigration age data
The dataframe for immigration age data
year
None