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

        Returns:
            age: A cleaned pandas dataframe
        """
        age = age[age['Type'] == 'total']
        van_total = age.sum()
        van_total['LocalArea'] = 'City of Vancouver'
        van_total['Type'] = 'total'
        age = age.append(van_total, ignore_index=True)

        age['Under 20'] = (age[
            '0 to 4 years'] + age[
            '5 to 9 years'] + age[
            '10 to 14 years'] + age[
            '15 to 19 years'])

        age['20 to 34'] = (age[
            '20 to 24 years'] + age[
            '25 to 29 years'] + age[
            '30 to 34 years'])

        age['35 to 44'] = (age[
            '35 to 39 years'] + age[
            '40 to 44 years'])

        age['45 to 54'] = (age[
            '45 to 49 years'] + age[
            '50 to 54 years'])

        age['55 to 64'] = (age[
            '55 to 59 years'] + age[
            '60 to 64 years'])

        age['65 to 79'] = (age[
            '65 to 69 years'] + age[
            '70 to 74 years'] + age[
            '75 to 79 years'])

        if year in [2001, 2006]:

            age['80 and Older'] = (age[
                '80 to 84 years'] + age[
                '85 to 89 years'] + age[
                '90 to 94 years'] + age[
                '95 to 99 years'] + age[
                '100 years and over'])

        elif year in [2011, 2016]:

            age['80 and Older'] = (age[
                '80 to 84 years'] + age[
                '85 years and over'])

        age['Age_total'] = (age[
                   'Under 20'] + age[
                   '20 to 34'] + age[
                   '35 to 44'] + age[
                   '45 to 54'] + age[
                   '55 to 64'] + age[
                   '65 to 79'] + age[
                   '80 and Older'])
        age['Under 20'] = age['Under 20'] / age['Age_total']
        age['20 to 34'] = age['20 to 34'] / age['Age_total']
        age['35 to 44'] = age['35 to 44'] / age['Age_total']
        age['45 to 54'] = age['45 to 54'] / age['Age_total']
        age['55 to 64'] = age['55 to 64'] / age['Age_total']
        age['65 to 79'] = age['65 to 79'] / age['Age_total']
        age['80 and Older'] = age['80 and Older'] / age['Age_total']

        age = age[['LocalArea',
                   'Age_total',
                   'Under 20',
                   '20 to 34',
                   '35 to 44',
                   '45 to 54',
                   '55 to 64',
                   '65 to 79',
                   '80 and Older']]

        return age

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

        Returns:
            age: A cleaned pandas dataframe
        
This function cleans the population age census data
This function cleans the population age census data
def clean_population_age_sex(age, year):
        age = age[age['Type'] == 'total']
        van_total = age.sum()
        van_total['LocalArea'] = 'City of Vancouver'
        van_total['Type'] = 'total'
        age = age.append(van_total, ignore_index=True)
        age['Under 20'] = (age[
            '0 to 4 years'] + age[
            '5 to 9 years'] + age[
            '10 to 14 years'] + age[
            '15 to 19 years'])
        age['20 to 34'] = (age[
            '20 to 24 years'] + age[
            '25 to 29 years'] + age[
            '30 to 34 years'])
        age['35 to 44'] = (age[
            '35 to 39 years'] + age[
            '40 to 44 years'])
        age['45 to 54'] = (age[
            '45 to 49 years'] + age[
            '50 to 54 years'])
        age['55 to 64'] = (age[
            '55 to 59 years'] + age[
            '60 to 64 years'])
        age['65 to 79'] = (age[
            '65 to 69 years'] + age[
            '70 to 74 years'] + age[
            '75 to 79 years'])
        if year in [2001, 2006]:
            age['80 and Older'] = (age[
                '80 to 84 years'] + age[
                '85 to 89 years'] + age[
                '90 to 94 years'] + age[
                '95 to 99 years'] + age[
                '100 years and over'])
        elif year in [2011, 2016]:
            age['80 and Older'] = (age[
                '80 to 84 years'] + age[
                '85 years and over'])
        age['Age_total'] = (age[
                   'Under 20'] + age[
                   '20 to 34'] + age[
                   '35 to 44'] + age[
                   '45 to 54'] + age[
                   '55 to 64'] + age[
                   '65 to 79'] + age[
                   '80 and Older'])
        age['Under 20'] = age['Under 20'] / age['Age_total']
        age['20 to 34'] = age['20 to 34'] / age['Age_total']
        age['35 to 44'] = age['35 to 44'] / age['Age_total']
        age['45 to 54'] = age['45 to 54'] / age['Age_total']
        age['55 to 64'] = age['55 to 64'] / age['Age_total']
        age['65 to 79'] = age['65 to 79'] / age['Age_total']
        age['80 and Older'] = age['80 and Older'] / age['Age_total']
        age = age[['LocalArea',
                   'Age_total',
                   'Under 20',
                   '20 to 34',
                   '35 to 44',
                   '45 to 54',
                   '55 to 64',
                   '65 to 79',
                   '80 and Older']]
        return age
def clean_population_age_sex ( age , year ) : age = age [ age [ 'Type' ] == 'total' ] van_total = age . sum ( ) van_total [ 'LocalArea' ] = 'City of Vancouver' van_total [ 'Type' ] = 'total' age = age . append ( van_total , ignore_index = True ) age [ 'Under 20' ] = ( age [ '0 to 4 years' ] + age [ '5 to 9 years' ] + age [ '10 to 14 years' ] + age [ '15 to 19 years' ] ) age [ '20 to 34' ] = ( age [ '20 to 24 years' ] + age [ '25 to 29 years' ] + age [ '30 to 34 years' ] ) age [ '35 to 44' ] = ( age [ '35 to 39 years' ] + age [ '40 to 44 years' ] ) age [ '45 to 54' ] = ( age [ '45 to 49 years' ] + age [ '50 to 54 years' ] ) age [ '55 to 64' ] = ( age [ '55 to 59 years' ] + age [ '60 to 64 years' ] ) age [ '65 to 79' ] = ( age [ '65 to 69 years' ] + age [ '70 to 74 years' ] + age [ '75 to 79 years' ] ) if year in [ 2001 , 2006 ] : age [ '80 and Older' ] = ( age [ '80 to 84 years' ] + age [ '85 to 89 years' ] + age [ '90 to 94 years' ] + age [ '95 to 99 years' ] + age [ '100 years and over' ] ) elif year in [ 2011 , 2016 ] : age [ '80 and Older' ] = ( age [ '80 to 84 years' ] + age [ '85 years and over' ] ) age [ 'Age_total' ] = ( age [ 'Under 20' ] + age [ '20 to 34' ] + age [ '35 to 44' ] + age [ '45 to 54' ] + age [ '55 to 64' ] + age [ '65 to 79' ] + age [ '80 and Older' ] ) age [ 'Under 20' ] = age [ 'Under 20' ] / age [ 'Age_total' ] age [ '20 to 34' ] = age [ '20 to 34' ] / age [ 'Age_total' ] age [ '35 to 44' ] = age [ '35 to 44' ] / age [ 'Age_total' ] age [ '45 to 54' ] = age [ '45 to 54' ] / age [ 'Age_total' ] age [ '55 to 64' ] = age [ '55 to 64' ] / age [ 'Age_total' ] age [ '65 to 79' ] = age [ '65 to 79' ] / age [ 'Age_total' ] age [ '80 and Older' ] = age [ '80 and Older' ] / age [ 'Age_total' ] age = age [ [ 'LocalArea' , 'Age_total' , 'Under 20' , '20 to 34' , '35 to 44' , '45 to 54' , '55 to 64' , '65 to 79' , '80 and Older' ] ] return age
This function cleans the population age census data
This function cleans the population age census data
"""
        This function cleans the population age census data
        Args:
            age (pd.DataFrame): The dataframe for population data
            year (int) : Census year

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