Remove unused town numbers in statistics

This commit is contained in:
Yorick Barbanneau 2022-05-02 00:53:52 +02:00
parent 8eeea264d0
commit 8d00290dd2

View file

@ -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)