Import statistics csv
This commit is contained in:
parent
3d8c01e3c7
commit
6f48b59da9
1 changed files with 29 additions and 1 deletions
30
create_db.py
30
create_db.py
|
@ -51,6 +51,9 @@ def parse_args():
|
|||
parser.add_argument('--states',
|
||||
help='states raw csv file (inside source follder)',
|
||||
default='region2021.csv')
|
||||
parser.add_argument('--statistics',
|
||||
help='statistics raw csv file to import',
|
||||
default='statistiques.csv')
|
||||
debug_group = parser.add_mutually_exclusive_group()
|
||||
debug_group.add_argument('--verbose', '-V',
|
||||
help='Verbose output',
|
||||
|
@ -98,6 +101,26 @@ def import_towns_csv(raw_file):
|
|||
return towns.loc[towns['TYPECOM'] == 'COM', ['COM','NCC', 'LIBELLE', 'DEP']]
|
||||
|
||||
|
||||
|
||||
def import_statistics_csv(raw_file):
|
||||
"""
|
||||
Process stats files
|
||||
"""
|
||||
|
||||
logger.info('import town from {}'.format(raw_file))
|
||||
stats = pd.read_csv(raw_file,
|
||||
usecols=["CODGEO","SUPERF","P18_POP","P13_POP","P08_POP","D99_POP",
|
||||
"NAIS1318","NAIS0813","NAIS9908","NAIS9099","NAIS8290","DECE1318",
|
||||
"DECE0813","DECE9908","DECE9099","DECE8290","P18_LOG","P13_LOG",
|
||||
"P08_LOG","D99_LOG","D90_LOG","D82_LOG", "P18_LOGVAC","P13_LOGVAC",
|
||||
"P08_LOGVAC","D99_LOGVAC","D90_LOGVAC","D82_LOGVAC","P18_RP",
|
||||
"P13_RP","P08_RP","D99_RP","D90_RP","D82_RP", "P18_RSECOCC",
|
||||
"P13_RSECOCC","P08_RSECOCC","D99_RSECOCC","D90_RSECOCC",
|
||||
"D82_RSECOCC"],
|
||||
sep=';')
|
||||
return stats
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = parse_args()
|
||||
|
||||
|
@ -117,7 +140,6 @@ if __name__ == '__main__':
|
|||
logger.setLevel(logging.DEBUG)
|
||||
logger.debug('DEBUG mode activated')
|
||||
|
||||
|
||||
if not os.path.exists(args.source + '/' + args.states):
|
||||
logger.critical('can\'t find source file for states')
|
||||
sys.exit(1)
|
||||
|
@ -137,4 +159,10 @@ if __name__ == '__main__':
|
|||
towns = import_towns_csv(args.source + '/' + args.towns)
|
||||
logger.debug(towns)
|
||||
|
||||
if not os.path.exists(args.source + '/' + args.statistics):
|
||||
logger.critical('can\'t find source file for statistics')
|
||||
sys.exit(1)
|
||||
statistics = import_statistics_csv(args.source + '/' + args.statistics)
|
||||
logger.debug(statistics)
|
||||
|
||||
sys.exit()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue