def main(_):
    indicator_codes = pd.read_csv('WorldBankIndicators.csv')

    def add_source_to_description(row):
        if (not pd.isna(row['Source'])):
            return ((row['SourceNote'] + ' ') + str(row['Source']))
        else:
            return row['SourceNote']
    indicator_codes['SourceNote'] = indicator_codes.apply(add_source_to_description, axis=1)
    with open('output/WorldBank_StatisticalVariables.mcf', 'w+') as f_out:
        for (_, row) in indicator_codes[indicator_codes['ExistingStatVar'].isna()].iterrows():
            f_out.write(build_stat_vars_from_indicator_list(row))
    tmcfs_for_stat_vars = group_stat_vars_by_observation_properties(indicator_codes)
    worldbank_countries = pd.read_csv('WorldBankCountries.csv')
    worldbank_dataframe = download_indicator_data(worldbank_countries, indicator_codes)
    worldbank_dataframe['Value'] = pd.to_numeric(worldbank_dataframe['Value'])
    worldbank_dataframe['ISO3166Alpha3'] = worldbank_dataframe['ISO3166Alpha3'].apply((lambda code: ('dcs:country/' + code)))
    worldbank_dataframe['StatisticalVariable'] = worldbank_dataframe['StatisticalVariable'].apply((lambda code: ('dcs:' + code)))
    scaling_factor_lookup = indicator_codes.set_index('IndicatorCode')['sourceScalingFactor'].dropna().to_dict()
    existing_stat_var_lookup = indicator_codes.set_index('IndicatorCode')['ExistingStatVar'].dropna().to_dict()
    worldbank_dataframe = worldbank_dataframe.apply((lambda row: source_scaling_remap(row, scaling_factor_lookup, existing_stat_var_lookup)), axis=1)
    int_cols = list(indicator_codes[(indicator_codes['ConvertToInt'] == True)]['IndicatorCode'].unique())
    worldbank_subset = worldbank_dataframe[worldbank_dataframe['IndicatorCode'].isin(int_cols)].index
    worldbank_dataframe.loc[(worldbank_subset, 'Value')] = pd.to_numeric(worldbank_dataframe.loc[(worldbank_subset, 'Value')], downcast='integer')
    output_csv_and_tmcf_by_grouping(worldbank_dataframe, tmcfs_for_stat_vars, indicator_codes)
def main(_):
    indicator_codes = pd.read_csv('WorldBankIndicators.csv')

    def add_source_to_description(row):
        if (not pd.isna(row['Source'])):
            return ((row['SourceNote'] + ' ') + str(row['Source']))
        else:
            return row['SourceNote']
    indicator_codes['SourceNote'] = indicator_codes.apply(add_source_to_description, axis=1)
    with open('output/WorldBank_StatisticalVariables.mcf', 'w+') as f_out:
        for (_, row) in indicator_codes[indicator_codes['ExistingStatVar'].isna()].iterrows():
            f_out.write(build_stat_vars_from_indicator_list(row))
    tmcfs_for_stat_vars = group_stat_vars_by_observation_properties(indicator_codes)
    worldbank_countries = pd.read_csv('WorldBankCountries.csv')
    worldbank_dataframe = download_indicator_data(worldbank_countries, indicator_codes)
    worldbank_dataframe['Value'] = pd.to_numeric(worldbank_dataframe['Value'])
    worldbank_dataframe['ISO3166Alpha3'] = worldbank_dataframe['ISO3166Alpha3'].apply((lambda code: ('dcs:country/' + code)))
    worldbank_dataframe['StatisticalVariable'] = worldbank_dataframe['StatisticalVariable'].apply((lambda code: ('dcs:' + code)))
    scaling_factor_lookup = indicator_codes.set_index('IndicatorCode')['sourceScalingFactor'].dropna().to_dict()
    existing_stat_var_lookup = indicator_codes.set_index('IndicatorCode')['ExistingStatVar'].dropna().to_dict()
    worldbank_dataframe = worldbank_dataframe.apply((lambda row: source_scaling_remap(row, scaling_factor_lookup, existing_stat_var_lookup)), axis=1)
    int_cols = list(indicator_codes[(indicator_codes['ConvertToInt'] == True)]['IndicatorCode'].unique())
    worldbank_subset = worldbank_dataframe[worldbank_dataframe['IndicatorCode'].isin(int_cols)].index
    worldbank_dataframe.loc[(worldbank_subset, 'Value')] = pd.to_numeric(worldbank_dataframe.loc[(worldbank_subset, 'Value')], downcast='integer')
    output_csv_and_tmcf_by_grouping(worldbank_dataframe, tmcfs_for_stat_vars, indicator_codes)