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

        Returns:
            language: A cleaned pandas dataframe
        """

        # only keeping their mother tongue
        language = language[language['Type'] == 'mother tongue - total']

        van_total = language.sum()
        van_total['LocalArea'] = 'City of Vancouver'
        van_total['Type'] = 'mother tongue - total'
        language = language.append(van_total, ignore_index=True)

        if year == 2001:
            cols = ['English', 'French', 'Chinese, n.o.s.',
                    'Mandarin', 'Cantonese', 'Italian',
                    'German', 'Spanish', 'Punjabi', 'Tagalog (Pilipino)',
                    'Vietnamese', 'Korean', 'Hindi', 'Persian (Farsi)']
        elif year in [2006, 2011]:
            cols = ['English', 'French', 'Chinese, n.o.s.',
                    'Mandarin', 'Cantonese', 'Italian',
                    'German', 'Spanish', 'Panjabi (Punjabi)',
                    'Tagalog (Pilipino, Filipino)',
                    'Vietnamese', 'Korean', 'Hindi', 'Persian (Farsi)']

        else:
            cols = ['English', 'French', 'Chinese languages',
                    'Italian', 'German', 'Spanish', 'Punjabi (Panjabi)',
                    'Tagalog (Pilipino, Filipino)',
                    'Vietnamese', 'Korean', 'Hindi', 'Persian (Farsi)']

        # calculate percentages
        for c in cols:
            language[c] = language[c]/language['Single responses']

        # group together Chinese languages
        if year in [2001, 2006, 2011]:
            language['Chinese languages'] = language['Mandarin'] + \
                language['Cantonese'] + \
                language['Chinese, n.o.s.']

        # standardize spelling of languages
        if year in [2006, 2011, 2016]:
            language['Tagalog (Filipino)'] = language['Tagalog (Pilipino, Filipino)']
            if year == 2016:
                language['Panjabi (Punjabi)'] = language['Punjabi (Panjabi)']
        else:
            language['Panjabi (Punjabi)'] = language['Punjabi']
            language['Tagalog (Filipino)'] = language['Tagalog (Pilipino)']
        language['Korean language'] = language['Korean']

        language = language[['LocalArea', 'English',
                             'French', 'Chinese languages',
                             'Tagalog (Filipino)',
                             'Panjabi (Punjabi)',
                             'Italian', 'German',
                             'Spanish', 'Vietnamese',
                             'Korean language', 'Hindi',
                             'Persian (Farsi)']]

        return language

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

        Returns:
            language: A cleaned pandas dataframe
        
This function cleans the language census data
This function cleans the language census data
def clean_detailed_language(language, year):
        language = language[language['Type'] == 'mother tongue - total']
        van_total = language.sum()
        van_total['LocalArea'] = 'City of Vancouver'
        van_total['Type'] = 'mother tongue - total'
        language = language.append(van_total, ignore_index=True)
        if year == 2001:
            cols = ['English', 'French', 'Chinese, n.o.s.',
                    'Mandarin', 'Cantonese', 'Italian',
                    'German', 'Spanish', 'Punjabi', 'Tagalog (Pilipino)',
                    'Vietnamese', 'Korean', 'Hindi', 'Persian (Farsi)']
        elif year in [2006, 2011]:
            cols = ['English', 'French', 'Chinese, n.o.s.',
                    'Mandarin', 'Cantonese', 'Italian',
                    'German', 'Spanish', 'Panjabi (Punjabi)',
                    'Tagalog (Pilipino, Filipino)',
                    'Vietnamese', 'Korean', 'Hindi', 'Persian (Farsi)']
        else:
            cols = ['English', 'French', 'Chinese languages',
                    'Italian', 'German', 'Spanish', 'Punjabi (Panjabi)',
                    'Tagalog (Pilipino, Filipino)',
                    'Vietnamese', 'Korean', 'Hindi', 'Persian (Farsi)']
        for c in cols:
            language[c] = language[c]/language['Single responses']
        if year in [2001, 2006, 2011]:
            language['Chinese languages'] = language['Mandarin'] + \
                language['Cantonese'] + \
                language['Chinese, n.o.s.']
        if year in [2006, 2011, 2016]:
            language['Tagalog (Filipino)'] = language['Tagalog (Pilipino, Filipino)']
            if year == 2016:
                language['Panjabi (Punjabi)'] = language['Punjabi (Panjabi)']
        else:
            language['Panjabi (Punjabi)'] = language['Punjabi']
            language['Tagalog (Filipino)'] = language['Tagalog (Pilipino)']
        language['Korean language'] = language['Korean']
        language = language[['LocalArea', 'English',
                             'French', 'Chinese languages',
                             'Tagalog (Filipino)',
                             'Panjabi (Punjabi)',
                             'Italian', 'German',
                             'Spanish', 'Vietnamese',
                             'Korean language', 'Hindi',
                             'Persian (Farsi)']]
        return language
def clean_detailed_language ( language , year ) : language = language [ language [ 'Type' ] == 'mother tongue - total' ] van_total = language . sum ( ) van_total [ 'LocalArea' ] = 'City of Vancouver' van_total [ 'Type' ] = 'mother tongue - total' language = language . append ( van_total , ignore_index = True ) if year == 2001 : cols = [ 'English' , 'French' , 'Chinese, n.o.s.' , 'Mandarin' , 'Cantonese' , 'Italian' , 'German' , 'Spanish' , 'Punjabi' , 'Tagalog (Pilipino)' , 'Vietnamese' , 'Korean' , 'Hindi' , 'Persian (Farsi)' ] elif year in [ 2006 , 2011 ] : cols = [ 'English' , 'French' , 'Chinese, n.o.s.' , 'Mandarin' , 'Cantonese' , 'Italian' , 'German' , 'Spanish' , 'Panjabi (Punjabi)' , 'Tagalog (Pilipino, Filipino)' , 'Vietnamese' , 'Korean' , 'Hindi' , 'Persian (Farsi)' ] else : cols = [ 'English' , 'French' , 'Chinese languages' , 'Italian' , 'German' , 'Spanish' , 'Punjabi (Panjabi)' , 'Tagalog (Pilipino, Filipino)' , 'Vietnamese' , 'Korean' , 'Hindi' , 'Persian (Farsi)' ] for c in cols : language [ c ] = language [ c ] / language [ 'Single responses' ] if year in [ 2001 , 2006 , 2011 ] : language [ 'Chinese languages' ] = language [ 'Mandarin' ] + language [ 'Cantonese' ] + language [ 'Chinese, n.o.s.' ] if year in [ 2006 , 2011 , 2016 ] : language [ 'Tagalog (Filipino)' ] = language [ 'Tagalog (Pilipino, Filipino)' ] if year == 2016 : language [ 'Panjabi (Punjabi)' ] = language [ 'Punjabi (Panjabi)' ] else : language [ 'Panjabi (Punjabi)' ] = language [ 'Punjabi' ] language [ 'Tagalog (Filipino)' ] = language [ 'Tagalog (Pilipino)' ] language [ 'Korean language' ] = language [ 'Korean' ] language = language [ [ 'LocalArea' , 'English' , 'French' , 'Chinese languages' , 'Tagalog (Filipino)' , 'Panjabi (Punjabi)' , 'Italian' , 'German' , 'Spanish' , 'Vietnamese' , 'Korean language' , 'Hindi' , 'Persian (Farsi)' ] ] return language
This function cleans the language census data
This function cleans the language census data
"""
        This function cleans the language census data
        Args:
            language (pd.DataFrame): The dataframe for language data
            year (int) : Census year

        Returns:
            language: A cleaned pandas dataframe
        """ # only keeping their mother tongue # calculate percentages # group together Chinese languages # standardize spelling of languages
A cleaned pandas dataframe
A cleaned pandas dataframe
language
language
The dataframe for language data
The dataframe for language data
year
None