Skip to content

Commit c7234fc

Browse files
Merge pull request #2091 from plotly/geodataset
add a geojson dataset and link from election dataset
2 parents 4c32bd5 + 9b14481 commit c7234fc

File tree

3 files changed

+60
-29
lines changed

3 files changed

+60
-29
lines changed

Diff for: packages/python/plotly/plotly/data/__init__.py

+60-29
Original file line numberDiff line numberDiff line change
@@ -5,69 +5,100 @@
55

66
def gapminder():
77
"""
8-
Each row represents a country on a given year.
8+
Each row represents a country on a given year.
99
10-
https://www.gapminder.org/data/
10+
https://www.gapminder.org/data/
1111
12-
Returns:
13-
A `pandas.DataFrame` with 1704 rows and the following columns: `['country', 'continent', 'year', 'lifeExp', 'pop', 'gdpPercap',
14-
'iso_alpha', 'iso_num']`.
15-
"""
12+
Returns:
13+
A `pandas.DataFrame` with 1704 rows and the following columns:
14+
`['country', 'continent', 'year', 'lifeExp', 'pop', 'gdpPercap',
15+
'iso_alpha', 'iso_num']`.
16+
"""
1617
return _get_dataset("gapminder")
1718

1819

1920
def tips():
2021
"""
21-
Each row represents a restaurant bill.
22+
Each row represents a restaurant bill.
2223
23-
https://vincentarelbundock.github.io/Rdatasets/doc/reshape2/tips.html
24+
https://vincentarelbundock.github.io/Rdatasets/doc/reshape2/tips.html
2425
25-
Returns:
26-
A `pandas.DataFrame` with 244 rows and the following columns: `['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']`.
27-
"""
26+
Returns:
27+
A `pandas.DataFrame` with 244 rows and the following columns:
28+
`['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']`.
29+
"""
2830
return _get_dataset("tips")
2931

3032

3133
def iris():
3234
"""
33-
Each row represents a flower.
35+
Each row represents a flower.
3436
35-
https://en.wikipedia.org/wiki/Iris_flower_data_set
37+
https://en.wikipedia.org/wiki/Iris_flower_data_set
3638
37-
Returns:
38-
A `pandas.DataFrame` with 150 rows and the following columns: `['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species',
39-
'species_id']`.
40-
"""
39+
Returns:
40+
A `pandas.DataFrame` with 150 rows and the following columns:
41+
`['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species', 'species_id']`.
42+
"""
4143
return _get_dataset("iris")
4244

4345

4446
def wind():
4547
"""
46-
Each row represents a level of wind intensity in a cardinal direction, and its frequency.
48+
Each row represents a level of wind intensity in a cardinal direction, and its frequency.
4749
48-
Returns:
49-
A `pandas.DataFrame` with 128 rows and the following columns: `['direction', 'strength', 'frequency']`.
50-
"""
50+
Returns:
51+
A `pandas.DataFrame` with 128 rows and the following columns:
52+
`['direction', 'strength', 'frequency']`.
53+
"""
5154
return _get_dataset("wind")
5255

5356

5457
def election():
5558
"""
56-
Each row represents voting results for an electoral district in the 2013 Montreal mayoral election.
59+
Each row represents voting results for an electoral district in the 2013 Montreal
60+
mayoral election.
5761
58-
Returns:
59-
A `pandas.DataFrame` with 58 rows and the following columns: `['district', 'Coderre', 'Bergeron', 'Joly', 'total', 'winner', 'result']`.
60-
"""
62+
Returns:
63+
A `pandas.DataFrame` with 58 rows and the following columns:
64+
`['district', 'Coderre', 'Bergeron', 'Joly', 'total', 'winner', 'result', 'district_id']`.
65+
"""
6166
return _get_dataset("election")
6267

6368

64-
def carshare():
69+
def election_geojson():
6570
"""
66-
Each row represents the availability of car-sharing services near the centroid of a zone in Montreal.
71+
Each feature represents an electoral district in the 2013 Montreal mayoral election.
72+
73+
Returns:
74+
A GeoJSON-formatted `dict` with 58 polygon or multi-polygon features whose `id`
75+
is an electoral district numerical ID and whose `district` property is the ID and
76+
district name.
77+
"""
78+
import gzip
79+
import json
80+
import os
81+
82+
path = os.path.join(
83+
os.path.dirname(os.path.dirname(__file__)),
84+
"package_data",
85+
"datasets",
86+
"election.geojson.gz",
87+
)
88+
with gzip.GzipFile(path, "r") as f:
89+
result = json.loads(f.read().decode("utf-8"))
90+
return result
91+
6792

68-
Returns:
69-
A `pandas.DataFrame` with 249 rows and the following columns: `['centroid_lat', 'centroid_lon', 'car_hours', 'peak_hour']`.
93+
def carshare():
7094
"""
95+
Each row represents the availability of car-sharing services near the centroid of a zone
96+
in Montreal.
97+
98+
Returns:
99+
A `pandas.DataFrame` with 249 rows and the following columns:
100+
`['centroid_lat', 'centroid_lon', 'car_hours', 'peak_hour']`.
101+
"""
71102
return _get_dataset("carshare")
72103

73104

Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)