src/02_clean_wrangle/06_synthesis.py
def clean_detailed_language(language, start_year, end_year):
        """
        This function cleans the language census data
        Args:
            language (pandas dataframe): The dataframe for language data
            start_year (int): The four digit start year
            end_year (int): The four digit end year, note end year not included

        Returns:
            language: A cleaned pandas dataframe

        """
        assert check_columns(language, ['Type', 'LocalArea','English', 'French', 'Chinese, n.o.s.',
                'Mandarin', 'Cantonese', 'Italian',
                'German', 'Spanish']), 'Input dataframe does not have all columns required'

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

        cols = ['English', 'French', 'Chinese, n.o.s.',
                'Mandarin', 'Cantonese', 'Italian',
                'German', 'Spanish']

        sum_language = 0
        for c in cols:
            language[c] = language[c]/language['Single responses']
            sum_language += language[c]

        language['other language'] = 1 - sum_language

        language['Chinese'] = language['Mandarin'] + \
            language['Cantonese'] + \
            language['Chinese, n.o.s.']

        language = language[['LocalArea', 'English',
                             'French', 'Chinese',
                             'Italian', 'German',
                             'Spanish', 'other language']]

        language = fill_missing_year(
            language, start_year, end_year)
        return language

        This function cleans the language census data
        Args:
            language (pandas dataframe): The dataframe for language data
            start_year (int): The four digit start year
            end_year (int): The four digit end year, note end year not included

        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, start_year, end_year):
        assert check_columns(language, ['Type', 'LocalArea','English', 'French', 'Chinese, n.o.s.',
                'Mandarin', 'Cantonese', 'Italian',
                'German', 'Spanish']), 'Input dataframe does not have all columns required'
        language = language[language['Type'] == 'mother tongue - total']
        cols = ['English', 'French', 'Chinese, n.o.s.',
                'Mandarin', 'Cantonese', 'Italian',
                'German', 'Spanish']
        sum_language = 0
        for c in cols:
            language[c] = language[c]/language['Single responses']
            sum_language += language[c]
        language['other language'] = 1 - sum_language
        language['Chinese'] = language['Mandarin'] + \
            language['Cantonese'] + \
            language['Chinese, n.o.s.']
        language = language[['LocalArea', 'English',
                             'French', 'Chinese',
                             'Italian', 'German',
                             'Spanish', 'other language']]
        language = fill_missing_year(
            language, start_year, end_year)
        return language
def clean_detailed_language ( language , start_year , end_year ) : assert check_columns ( language , [ 'Type' , 'LocalArea' , 'English' , 'French' , 'Chinese, n.o.s.' , 'Mandarin' , 'Cantonese' , 'Italian' , 'German' , 'Spanish' ] ) , 'Input dataframe does not have all columns required' language = language [ language [ 'Type' ] == 'mother tongue - total' ] cols = [ 'English' , 'French' , 'Chinese, n.o.s.' , 'Mandarin' , 'Cantonese' , 'Italian' , 'German' , 'Spanish' ] sum_language = 0 for c in cols : language [ c ] = language [ c ] / language [ 'Single responses' ] sum_language += language [ c ] language [ 'other language' ] = 1 - sum_language language [ 'Chinese' ] = language [ 'Mandarin' ] + language [ 'Cantonese' ] + language [ 'Chinese, n.o.s.' ] language = language [ [ 'LocalArea' , 'English' , 'French' , 'Chinese' , 'Italian' , 'German' , 'Spanish' , 'other language' ] ] language = fill_missing_year ( language , start_year , end_year ) 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 (pandas dataframe): The dataframe for language data
            start_year (int): The four digit start year
            end_year (int): The four digit end year, note end year not included

        Returns:
            language: A cleaned pandas dataframe

        """ # only keeping their mother tongue
A cleaned pandas dataframe
A cleaned pandas dataframe
language
language
The dataframe for language data
The dataframe for language data
start_year
The four digit start year
The four digit start year
end_year
The four digit end year, note end year not included
The four digit end year note end year not included