src/04_visualization/census_vis_synthesis.py
def clean_citizenship(citizen, year):
        """
        This function cleans the citizenship census data
        Args:
            citizen (pd.DataFrame): The dataframe for citizenship data
            year (int): census year

        Returns:
            citizen: A cleaned pandas dataframe
        """

        if year == 2011:
            citizen = citizen[citizen['Unnamed: 0'] == 0]
            van_total = citizen.sum()
            van_total['LocalArea'] = 'City of Vancouver'
            van_total['Unnamed: 0'] = 0
            citizen = citizen.append(van_total, ignore_index=True)

        if year == 2001:
            citizen = citizen.rename(
                columns={'Canadian Citizenship': 'Canadian citizens',
                         'Citizenship other than Canadian': 'Not Canadian citizens'})

        citizen['total'] = citizen[
                'Canadian citizens'] + citizen[
                'Not Canadian citizens']

        citizen['Canadian citizens'] = citizen[
                'Canadian citizens'] / citizen['total']

        citizen['Not Canadian citizens'] = citizen[
                'Not Canadian citizens'] / citizen['total']

        citizen = citizen[['LocalArea',
                           'Canadian citizens',
                           'Not Canadian citizens']]

        return citizen

        This function cleans the citizenship census data
        Args:
            citizen (pd.DataFrame): The dataframe for citizenship data
            year (int): census year

        Returns:
            citizen: A cleaned pandas dataframe
        
This function cleans the citizenship census data
This function cleans the citizenship census data
def clean_citizenship(citizen, year):
        if year == 2011:
            citizen = citizen[citizen['Unnamed: 0'] == 0]
            van_total = citizen.sum()
            van_total['LocalArea'] = 'City of Vancouver'
            van_total['Unnamed: 0'] = 0
            citizen = citizen.append(van_total, ignore_index=True)
        if year == 2001:
            citizen = citizen.rename(
                columns={'Canadian Citizenship': 'Canadian citizens',
                         'Citizenship other than Canadian': 'Not Canadian citizens'})
        citizen['total'] = citizen[
                'Canadian citizens'] + citizen[
                'Not Canadian citizens']
        citizen['Canadian citizens'] = citizen[
                'Canadian citizens'] / citizen['total']
        citizen['Not Canadian citizens'] = citizen[
                'Not Canadian citizens'] / citizen['total']
        citizen = citizen[['LocalArea',
                           'Canadian citizens',
                           'Not Canadian citizens']]
        return citizen
def clean_citizenship ( citizen , year ) : if year == 2011 : citizen = citizen [ citizen [ 'Unnamed: 0' ] == 0 ] van_total = citizen . sum ( ) van_total [ 'LocalArea' ] = 'City of Vancouver' van_total [ 'Unnamed: 0' ] = 0 citizen = citizen . append ( van_total , ignore_index = True ) if year == 2001 : citizen = citizen . rename ( columns = { 'Canadian Citizenship' : 'Canadian citizens' , 'Citizenship other than Canadian' : 'Not Canadian citizens' } ) citizen [ 'total' ] = citizen [ 'Canadian citizens' ] + citizen [ 'Not Canadian citizens' ] citizen [ 'Canadian citizens' ] = citizen [ 'Canadian citizens' ] / citizen [ 'total' ] citizen [ 'Not Canadian citizens' ] = citizen [ 'Not Canadian citizens' ] / citizen [ 'total' ] citizen = citizen [ [ 'LocalArea' , 'Canadian citizens' , 'Not Canadian citizens' ] ] return citizen
This function cleans the citizenship census data
This function cleans the citizenship census data
"""
        This function cleans the citizenship census data
        Args:
            citizen (pd.DataFrame): The dataframe for citizenship data
            year (int): census year

        Returns:
            citizen: A cleaned pandas dataframe
        """
A cleaned pandas dataframe
A cleaned pandas dataframe
citizen
citizen
The dataframe for citizenship data
The dataframe for citizenship data
year
None