Skip to content

add pretty_names option to datasets #3347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions packages/python/plotly/plotly/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""


def gapminder(datetimes=False, centroids=False, year=None):
def gapminder(datetimes=False, centroids=False, year=None, pretty_names=False):
"""
Each row represents a country on a given year.

Expand All @@ -24,10 +24,27 @@ def gapminder(datetimes=False, centroids=False, year=None):
df["year"] = (df["year"].astype(str) + "-01-01").astype("datetime64[ns]")
if not centroids:
df = df.drop(["centroid_lat", "centroid_lon"], axis=1)
if pretty_names:
df.rename(
mapper=dict(
country="Country",
continent="Continent",
year="Year",
lifeExp="Life Expectancy",
gdpPercap="GDP per Capita",
pop="Population",
iso_alpha="ISO Alpha Country Code",
iso_num="ISO Numeric Country Code",
centroid_lat="Centroid Latitude",
centroid_lon="Centroid Longitude",
),
axis="columns",
inplace=True,
)
return df


def tips():
def tips(pretty_names=False):
"""
Each row represents a restaurant bill.

Expand All @@ -36,7 +53,23 @@ def tips():
Returns:
A `pandas.DataFrame` with 244 rows and the following columns:
`['total_bill', 'tip', 'sex', 'smoker', 'day', 'time', 'size']`."""
return _get_dataset("tips")

df = _get_dataset("tips")
if pretty_names:
df.rename(
mapper=dict(
total_bill="Total Bill",
tip="Tip",
sex="Payer Gender",
smoker="Smokers at Table",
day="Day of Week",
time="Meal",
size="Party Size",
),
axis="columns",
inplace=True,
)
return df


def iris():
Expand Down