Skip to content

Instantly share code, notes, and snippets.

@GuillaumePressiat
Last active September 8, 2017 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GuillaumePressiat/2c4e2db031d666f755742ec9fbf6e9d0 to your computer and use it in GitHub Desktop.
Save GuillaumePressiat/2c4e2db031d666f755742ec9fbf6e9d0 to your computer and use it in GitHub Desktop.
Découper le fichier Etalab Finess géocodé de data.gouv.fr
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Le fichier est dispo ici : https://www.data.gouv.fr/fr/datasets/finess-extraction-du-fichier-des-etablissements/
import os
os.chdir('..\\..\\')
print ('----------------- Découper Géocodage et structureET Etalab ---------------')
filin = open('data\\etalab_geolocalise\\etalab_cs1100507_stock_20170801-0442.csv')
filout = open('data\\etalab_geolocalise\\structureet_20170801', 'w')
with filin as infile:
for line in infile:
if line[0:11] == 'structureet':
# Suppression des = à la réécriture
filout.write(line[12:].replace("=\"", "\""))
filout.close()
filin = open('data\\etalab_geolocalise\\etalab_cs1100507_stock_20170801-0442.csv')
filout = open('data\\etalab_geolocalise\\geolocalisation_20170801', 'w')
with filin as infile:
for line in infile:
if line[0:15] == 'geolocalisation':
# Remplacer les , par des ; dans la partie géocodage et supprimer les =
filout.write(line[16:].replace(",", ";").replace("=\"", "\""))
filout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment