1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| path = 'C:/Users/id1015/Documents/Données/QE/queops'
file = 'MEETIQUE_29019_wgs_revgeo'
extension = '.xlsx'
df = pd.read_excel(f'{path}/{file}{extension}')
for idx, row in df.iterrows():
try:
df.loc[idx,'adresse'] = json.loads(row['reponse'])['features'][0]['properties']['label']
df.loc[idx,'housenumber'] = json.loads(row['reponse'])['features'][0]['properties']['housenumber']
df.loc[idx,'street'] = json.loads(row['reponse'])['features'][0]['properties']['street']
df.loc[idx,'postcode'] = json.loads(row['reponse'])['features'][0]['properties']['postcode']
df.loc[idx,'city'] = json.loads(row['reponse'])['features'][0]['properties']['city']
df.loc[idx,'insee'] = json.loads(row['reponse'])['features'][0]['properties']['citycode']
df.loc[idx,'id_adr'] = json.loads(row['reponse'])['features'][0]['properties']['id']
df.loc[idx,'score'] = json.loads(row['reponse'])['features'][0]['properties']['score']
df.loc[idx,'type'] = json.loads(row['reponse'])['features'][0]['properties']['type']
df.loc[idx,'x_l93'] = json.loads(row['reponse'])['features'][0]['properties']['x']
df.loc[idx,'y_l93'] = json.loads(row['reponse'])['features'][0]['properties']['y']
df.loc[idx,'distance'] = json.loads(row['reponse'])['features'][0]['properties']['distance']
except (KeyError, IndexError):
df.loc[idx,'adresse'] = np.nan
df.loc[idx,'housenumber'] = np.nan
df.loc[idx,'street'] = np.nan
df.loc[idx,'postcode'] = np.nan
df.loc[idx,'city'] = np.nan
df.loc[idx,'insee'] = np.nan
df.loc[idx,'id_adr'] = np.nan
df.loc[idx,'score'] = np.nan
df.loc[idx,'type'] = np.nan
df.loc[idx,'x_l93'] = np.nan
df.loc[idx,'y_l93'] = np.nan
df.loc[idx,'distance'] = np.nan
df.to_excel(f'{path}/{file}_comp{extension}',index=False) |
Partager