diff --git a/csvprocess.py b/csvprocess.py index f443181..c9c7040 100755 --- a/csvprocess.py +++ b/csvprocess.py @@ -82,6 +82,12 @@ def import_towns_csv(raw_file): return towns.loc[towns['TYPECOM'] == 'COM', ['COM','NCC', 'LIBELLE', 'DEP']] +def stats_convert(codegeo): + if len(codegeo) == 4: + return 0 + codegeo + if len(codegeo) == 6: + return codegeo[1:] + return codegeo def import_statistics_csv(raw_file): """ @@ -89,7 +95,6 @@ def import_statistics_csv(raw_file): """ logger.info('import town from {}'.format(raw_file)) - stats_convert= lambda x: x if len(str(x)) == 5 else f'0{x}' stats = pd.read_csv(raw_file, usecols=["CODGEO","SUPERF","P18_POP","P13_POP","P08_POP","D99_POP", "NAIS1318","NAIS0813","NAIS9908","NAIS9099","NAIS8290","DECE1318", @@ -201,6 +206,7 @@ if __name__ == '__main__': logger.critical('can\'t find source file for statistics') sys.exit(1) statistics = import_statistics_csv(args.source + '/' + args.statistics) + statistics = statistics[statistics['CODGEO'].isin(towns['COM'])] t.stop() logger.debug(statistics)