Process towns DataFrame
Add area colum from statistics
This commit is contained in:
parent
77456db238
commit
e0b69e18f1
1 changed files with 17 additions and 3 deletions
20
create_db.py
20
create_db.py
|
@ -111,6 +111,7 @@ def import_statistics_csv(raw_file):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
logger.info('import town from {}'.format(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,
|
stats = pd.read_csv(raw_file,
|
||||||
usecols=["CODGEO","SUPERF","P18_POP","P13_POP","P08_POP","D99_POP",
|
usecols=["CODGEO","SUPERF","P18_POP","P13_POP","P08_POP","D99_POP",
|
||||||
"NAIS1318","NAIS0813","NAIS9908","NAIS9099","NAIS8290","DECE1318",
|
"NAIS1318","NAIS0813","NAIS9908","NAIS9099","NAIS8290","DECE1318",
|
||||||
|
@ -120,7 +121,9 @@ def import_statistics_csv(raw_file):
|
||||||
"P13_RP","P08_RP","D99_RP","D90_RP","D82_RP", "P18_RSECOCC",
|
"P13_RP","P08_RP","D99_RP","D90_RP","D82_RP", "P18_RSECOCC",
|
||||||
"P13_RSECOCC","P08_RSECOCC","D99_RSECOCC","D90_RSECOCC",
|
"P13_RSECOCC","P08_RSECOCC","D99_RSECOCC","D90_RSECOCC",
|
||||||
"D82_RSECOCC"],
|
"D82_RSECOCC"],
|
||||||
sep=';')
|
sep=';',
|
||||||
|
converters={'CODGEO':stats_convert}
|
||||||
|
)
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
def get_single_date(attr):
|
def get_single_date(attr):
|
||||||
|
@ -241,8 +244,7 @@ if __name__ == '__main__':
|
||||||
## create statistics dataframes
|
## create statistics dataframes
|
||||||
#
|
#
|
||||||
# We need to first iterate on statistics
|
# We need to first iterate on statistics
|
||||||
if args.verbose or args.debug:
|
t.start('Process_Statistics')
|
||||||
t.start()
|
|
||||||
|
|
||||||
c_stats = pd.DataFrame(columns = ['com','id_indicateur','date_debut',
|
c_stats = pd.DataFrame(columns = ['com','id_indicateur','date_debut',
|
||||||
'date_fin','valeur']
|
'date_fin','valeur']
|
||||||
|
@ -290,6 +292,18 @@ if __name__ == '__main__':
|
||||||
temp['valeur'].append(value)
|
temp['valeur'].append(value)
|
||||||
|
|
||||||
t.stop()
|
t.stop()
|
||||||
|
|
||||||
|
t.start('Process_town')
|
||||||
|
print(statistics[['SUPERF','CODGEO']])
|
||||||
|
towns = pd.merge(towns,
|
||||||
|
statistics[['CODGEO', 'SUPERF']],
|
||||||
|
left_on=['COM'],
|
||||||
|
right_on=['CODGEO'],
|
||||||
|
how = 'left'
|
||||||
|
)[['COM','NCC','LIBELLE', 'DEP', 'SUPERF']]
|
||||||
|
t.stop()
|
||||||
|
logger.debug(towns)
|
||||||
|
|
||||||
t.get_total_time()
|
t.get_total_time()
|
||||||
|
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue