In [1]:
import requests
# Download the JSON file
remote_file_path = 'http://opendata.paris.fr/api/records/1.0/search/?dataset=arbresremarquablesparis&rows=200'
data_json = requests.get(remote_file_path).json()['records']
data_json[0].keys()
Out[1]:
dict_keys(['datasetid', 'recordid', 'fields', 'geometry', 'record_timestamp'])
In [2]:
from pandas import json_normalize
# Normalize the data
df = json_normalize(data_json)
df.head()
Out[2]:
datasetid
recordid
record_timestamp
fields.geom_x_y
fields.libellefrancais
fields.objectid
fields.idemplacement
fields.arrondissement
fields.circonferenceencm
fields.hauteurenm
...
fields.stadedeveloppement
fields.remarquable
fields.idbase
fields.genre
fields.typeemplacement
fields.dateplantation
geometry.type
geometry.coordinates
fields.varieteoucultivar
fields.complementadresse
0
arbresremarquablesparis
29a0ea77b5379a1e15b5c34d0ed8bbadb9f5789c
2020-05-08T10:45:25.056000+00:00
[48.8542732882, 2.33573525468]
Paulownia
7493
000101001
PARIS 6E ARRDT
295.0
20.0
...
M
1
216766.0
Paulownia
Arbre
1999-01-25T01:00:00+00:00
Point
[2.33573525468, 48.8542732882]
NaN
NaN
1
arbresremarquablesparis
24ab994e9b2b51c4a27394ec52f038c4faa5fc1c
2020-05-08T10:45:25.056000+00:00
[48.8217882346, 2.3228497157]
Hêtre
57013
00000174
PARIS 14E ARRDT
310.0
15.0
...
M
1
121632.0
Fagus
Arbre
1700-01-01T00:09:21+00:00
Point
[2.3228497157, 48.8217882346]
''Atropunicea''
14-09
2
arbresremarquablesparis
2138bdaedd6c46f681ff30904f8017a292fc2b3b
2020-05-08T10:45:25.056000+00:00
[48.8648326277, 2.25217460792]
Plaqueminier
58739
000501002
BOIS DE BOULOGNE
146.0
15.0
...
A
1
2002388.0
Diospyros
Arbre
1897-01-01T00:09:21+00:00
Point
[2.25217460792, 48.8648326277]
NaN
16-13
3
arbresremarquablesparis
63bc7232fe659c4585923d9e65e5275418c359b9
2020-05-08T10:45:25.056000+00:00
[48.8564741998, 2.39461847904]
Platane
70026
001802036
PARIS 20E ARRDT
407.0
23.0
...
M
1
223748.0
Platanus
Arbre
1700-01-01T00:09:21+00:00
Point
[2.39461847904, 48.8564741998]
NaN
148
4
arbresremarquablesparis
602c7b2fd878c56e5efc532739abb28d86d9f365
2020-05-08T10:45:25.056000+00:00
[48.831216573, 2.41167739693]
Cryptomeria
85651
12-13
BOIS DE VINCENNES
122.0
13.0
...
M
1
2002359.0
Cryptomeria
Arbre
1893-01-01T00:09:21+00:00
Point
[2.41167739693, 48.831216573]
NaN
12-13
5 rows × 24 columns
In [3]:
# Add Latitude and Longitude columns
df['lng'] = df.apply(lambda row: row['geometry.coordinates'][0], axis=1)
df['lat'] = df.apply(lambda row: row['geometry.coordinates'][1], axis=1)
df.head()
Out[3]:
datasetid
recordid
record_timestamp
fields.geom_x_y
fields.libellefrancais
fields.objectid
fields.idemplacement
fields.arrondissement
fields.circonferenceencm
fields.hauteurenm
...
fields.idbase
fields.genre
fields.typeemplacement
fields.dateplantation
geometry.type
geometry.coordinates
fields.varieteoucultivar
fields.complementadresse
lng
lat
0
arbresremarquablesparis
29a0ea77b5379a1e15b5c34d0ed8bbadb9f5789c
2020-05-08T10:45:25.056000+00:00
[48.8542732882, 2.33573525468]
Paulownia
7493
000101001
PARIS 6E ARRDT
295.0
20.0
...
216766.0
Paulownia
Arbre
1999-01-25T01:00:00+00:00
Point
[2.33573525468, 48.8542732882]
NaN
NaN
2.335735
48.854273
1
arbresremarquablesparis
24ab994e9b2b51c4a27394ec52f038c4faa5fc1c
2020-05-08T10:45:25.056000+00:00
[48.8217882346, 2.3228497157]
Hêtre
57013
00000174
PARIS 14E ARRDT
310.0
15.0
...
121632.0
Fagus
Arbre
1700-01-01T00:09:21+00:00
Point
[2.3228497157, 48.8217882346]
''Atropunicea''
14-09
2.322850
48.821788
2
arbresremarquablesparis
2138bdaedd6c46f681ff30904f8017a292fc2b3b
2020-05-08T10:45:25.056000+00:00
[48.8648326277, 2.25217460792]
Plaqueminier
58739
000501002
BOIS DE BOULOGNE
146.0
15.0
...
2002388.0
Diospyros
Arbre
1897-01-01T00:09:21+00:00
Point
[2.25217460792, 48.8648326277]
NaN
16-13
2.252175
48.864833
3
arbresremarquablesparis
63bc7232fe659c4585923d9e65e5275418c359b9
2020-05-08T10:45:25.056000+00:00
[48.8564741998, 2.39461847904]
Platane
70026
001802036
PARIS 20E ARRDT
407.0
23.0
...
223748.0
Platanus
Arbre
1700-01-01T00:09:21+00:00
Point
[2.39461847904, 48.8564741998]
NaN
148
2.394618
48.856474
4
arbresremarquablesparis
602c7b2fd878c56e5efc532739abb28d86d9f365
2020-05-08T10:45:25.056000+00:00
[48.831216573, 2.41167739693]
Cryptomeria
85651
12-13
BOIS DE VINCENNES
122.0
13.0
...
2002359.0
Cryptomeria
Arbre
1893-01-01T00:09:21+00:00
Point
[2.41167739693, 48.831216573]
NaN
12-13
2.411677
48.831217
5 rows × 26 columns
In [4]:
from geopandas import GeoDataFrame, points_from_xy
gdf = GeoDataFrame(df, geometry=points_from_xy(df['lng'], df['lat']))
gdf.head()
Out[4]:
datasetid
recordid
record_timestamp
fields.geom_x_y
fields.libellefrancais
fields.objectid
fields.idemplacement
fields.arrondissement
fields.circonferenceencm
fields.hauteurenm
...
fields.genre
fields.typeemplacement
fields.dateplantation
geometry.type
geometry.coordinates
fields.varieteoucultivar
fields.complementadresse
lng
lat
geometry
0
arbresremarquablesparis
29a0ea77b5379a1e15b5c34d0ed8bbadb9f5789c
2020-05-08T10:45:25.056000+00:00
[48.8542732882, 2.33573525468]
Paulownia
7493
000101001
PARIS 6E ARRDT
295.0
20.0
...
Paulownia
Arbre
1999-01-25T01:00:00+00:00
Point
[2.33573525468, 48.8542732882]
NaN
NaN
2.335735
48.854273
POINT (2.33574 48.85427)
1
arbresremarquablesparis
24ab994e9b2b51c4a27394ec52f038c4faa5fc1c
2020-05-08T10:45:25.056000+00:00
[48.8217882346, 2.3228497157]
Hêtre
57013
00000174
PARIS 14E ARRDT
310.0
15.0
...
Fagus
Arbre
1700-01-01T00:09:21+00:00
Point
[2.3228497157, 48.8217882346]
''Atropunicea''
14-09
2.322850
48.821788
POINT (2.32285 48.82179)
2
arbresremarquablesparis
2138bdaedd6c46f681ff30904f8017a292fc2b3b
2020-05-08T10:45:25.056000+00:00
[48.8648326277, 2.25217460792]
Plaqueminier
58739
000501002
BOIS DE BOULOGNE
146.0
15.0
...
Diospyros
Arbre
1897-01-01T00:09:21+00:00
Point
[2.25217460792, 48.8648326277]
NaN
16-13
2.252175
48.864833
POINT (2.25217 48.86483)
3
arbresremarquablesparis
63bc7232fe659c4585923d9e65e5275418c359b9
2020-05-08T10:45:25.056000+00:00
[48.8564741998, 2.39461847904]
Platane
70026
001802036
PARIS 20E ARRDT
407.0
23.0
...
Platanus
Arbre
1700-01-01T00:09:21+00:00
Point
[2.39461847904, 48.8564741998]
NaN
148
2.394618
48.856474
POINT (2.39462 48.85647)
4
arbresremarquablesparis
602c7b2fd878c56e5efc532739abb28d86d9f365
2020-05-08T10:45:25.056000+00:00
[48.831216573, 2.41167739693]
Cryptomeria
85651
12-13
BOIS DE VINCENNES
122.0
13.0
...
Cryptomeria
Arbre
1893-01-01T00:09:21+00:00
Point
[2.41167739693, 48.831216573]
NaN
12-13
2.411677
48.831217
POINT (2.41168 48.83122)
5 rows × 27 columns
In [5]:
from cartoframes.viz import Layer
Layer(gdf)
Out[5]:
:
StackTrace
">
Content source: CartoDB/cartoframes
Similar notebooks: