diff --git a/packages/python/plotly/plotly/data/__init__.py b/packages/python/plotly/plotly/data/__init__.py index e47a730822f..dfedcfd28a7 100644 --- a/packages/python/plotly/plotly/data/__init__.py +++ b/packages/python/plotly/plotly/data/__init__.py @@ -5,69 +5,100 @@ def gapminder(): """ - Each row represents a country on a given year. +Each row represents a country on a given year. - https://www.gapminder.org/data/ +https://www.gapminder.org/data/ - Returns: - A `pandas.DataFrame` with 1704 rows and the following columns: `['country', 'continent', 'year', 'lifeExp', 'pop', 'gdpPercap', - 'iso_alpha', 'iso_num']`. - """ +Returns: + A `pandas.DataFrame` with 1704 rows and the following columns: + `['country', 'continent', 'year', 'lifeExp', 'pop', 'gdpPercap', + 'iso_alpha', 'iso_num']`. +""" return _get_dataset("gapminder") def tips(): """ - Each row represents a restaurant bill. +Each row represents a restaurant bill. - https://vincentarelbundock.github.io/Rdatasets/doc/reshape2/tips.html +https://vincentarelbundock.github.io/Rdatasets/doc/reshape2/tips.html - Returns: - A `pandas.DataFrame` with 244 rows and the following columns: `['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']`. - """ +Returns: + A `pandas.DataFrame` with 244 rows and the following columns: + `['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']`. +""" return _get_dataset("tips") def iris(): """ - Each row represents a flower. +Each row represents a flower. - https://en.wikipedia.org/wiki/Iris_flower_data_set +https://en.wikipedia.org/wiki/Iris_flower_data_set - Returns: - A `pandas.DataFrame` with 150 rows and the following columns: `['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species', - 'species_id']`. - """ +Returns: + A `pandas.DataFrame` with 150 rows and the following columns: + `['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species', 'species_id']`. +""" return _get_dataset("iris") def wind(): """ - Each row represents a level of wind intensity in a cardinal direction, and its frequency. +Each row represents a level of wind intensity in a cardinal direction, and its frequency. - Returns: - A `pandas.DataFrame` with 128 rows and the following columns: `['direction', 'strength', 'frequency']`. - """ +Returns: + A `pandas.DataFrame` with 128 rows and the following columns: + `['direction', 'strength', 'frequency']`. +""" return _get_dataset("wind") def election(): """ - Each row represents voting results for an electoral district in the 2013 Montreal mayoral election. +Each row represents voting results for an electoral district in the 2013 Montreal +mayoral election. - Returns: - A `pandas.DataFrame` with 58 rows and the following columns: `['district', 'Coderre', 'Bergeron', 'Joly', 'total', 'winner', 'result']`. - """ +Returns: + A `pandas.DataFrame` with 58 rows and the following columns: + `['district', 'Coderre', 'Bergeron', 'Joly', 'total', 'winner', 'result', 'district_id']`. +""" return _get_dataset("election") -def carshare(): +def election_geojson(): """ - Each row represents the availability of car-sharing services near the centroid of a zone in Montreal. +Each feature represents an electoral district in the 2013 Montreal mayoral election. + +Returns: + A GeoJSON-formatted `dict` with 58 polygon or multi-polygon features whose `id` + is an electoral district numerical ID and whose `district` property is the ID and + district name. +""" + import gzip + import json + import os + + path = os.path.join( + os.path.dirname(os.path.dirname(__file__)), + "package_data", + "datasets", + "election.geojson.gz", + ) + with gzip.GzipFile(path, "r") as f: + result = json.loads(f.read().decode("utf-8")) + return result + - Returns: - A `pandas.DataFrame` with 249 rows and the following columns: `['centroid_lat', 'centroid_lon', 'car_hours', 'peak_hour']`. +def carshare(): """ +Each row represents the availability of car-sharing services near the centroid of a zone +in Montreal. + +Returns: + A `pandas.DataFrame` with 249 rows and the following columns: + `['centroid_lat', 'centroid_lon', 'car_hours', 'peak_hour']`. +""" return _get_dataset("carshare") diff --git a/packages/python/plotly/plotly/package_data/datasets/election.csv.gz b/packages/python/plotly/plotly/package_data/datasets/election.csv.gz index 9038c29a41e..e97ee221f16 100644 Binary files a/packages/python/plotly/plotly/package_data/datasets/election.csv.gz and b/packages/python/plotly/plotly/package_data/datasets/election.csv.gz differ diff --git a/packages/python/plotly/plotly/package_data/datasets/election.geojson.gz b/packages/python/plotly/plotly/package_data/datasets/election.geojson.gz new file mode 100644 index 00000000000..3cb20e44ddd Binary files /dev/null and b/packages/python/plotly/plotly/package_data/datasets/election.geojson.gz differ