Skip to content

Commit 5149596

Browse files
authored
DOC update gallery examples to load datasets from path (skrub-data#1940)
1 parent 8c4a8b4 commit 5149596

5 files changed

Lines changed: 27 additions & 14 deletions

File tree

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ Bug Fixes
5353
- Errors raised when a polars LazyFrame is passed where an eager DataFrame is
5454
expected are now clearer. :pr:`1916` by :user:`Jérôme Dockès <jeromedockes>`.
5555

56+
Documentation
57+
-------------
58+
- Updated gallery examples to load datasets from their file paths using
59+
``pd.read_csv()``, following the pattern established in :pr:`1852`.
60+
:pr:`1940` by :user:`MuditAtrey <MuditAtrey>`.
61+
5662
Release 0.7.2
5763
=============
5864

examples/0040_fuzzy_joining.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
# --------------------------------
3535
#
3636
# We import the happiness score table first:
37+
import pandas as pd
38+
3739
from skrub import datasets
3840

3941
happiness_data = datasets.fetch_country_happiness()
40-
df = happiness_data.happiness_report
42+
df = pd.read_csv(happiness_data.happiness_report_path)
4143

4244
###############################################################################
4345
# Let's look at the table:
@@ -65,17 +67,17 @@
6567
# <https://data.worldbank.org/>`_, which are also available in the dataset
6668
# We extract the table containing GDP per capita by country:
6769

68-
gdp_per_capita = happiness_data.GDP_per_capita
70+
gdp_per_capita = pd.read_csv(happiness_data.GDP_per_capita_path)
6971
gdp_per_capita.head(3)
7072

7173
###############################################################################
7274
# Then another table, with life expectancy by country:
73-
life_exp = happiness_data.life_expectancy
75+
life_exp = pd.read_csv(happiness_data.life_expectancy_path)
7476
life_exp.head(3)
7577

7678
###############################################################################
7779
# And a table with legal rights strength by country:
78-
legal_rights = happiness_data.legal_rights_index
80+
legal_rights = pd.read_csv(happiness_data.legal_rights_index_path)
7981
legal_rights.head(3)
8082

8183
###############################################################################

examples/0060_multiple_key_join.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
dataset = fetch_flight_delays()
5151
seed = 1
52-
flights = dataset.flights
52+
flights = pd.read_csv(dataset.flights_path)
5353

5454
# Sampling for faster computation.
5555
flights = flights.sample(5_000, random_state=seed, ignore_index=True)
@@ -76,7 +76,7 @@
7676
# - The ``airports`` dataset, with information such as their name
7777
# and location (longitude, latitude).
7878

79-
airports = dataset.airports
79+
airports = pd.read_csv(dataset.airports_path)
8080
airports.head()
8181

8282
########################################################################
@@ -86,7 +86,7 @@
8686
# Both tables are from the Global Historical Climatology Network.
8787
# Here, we consider only weather measurements from 2008.
8888

89-
weather = dataset.weather
89+
weather = pd.read_csv(dataset.weather_path)
9090
# Sampling for faster computation.
9191
weather = weather.sample(10_000, random_state=seed, ignore_index=True)
9292
weather.head()
@@ -95,7 +95,7 @@
9595
# - The ``stations`` dataset. Provides location of all the weather
9696
# measurement stations in the US.
9797

98-
stations = dataset.stations
98+
stations = pd.read_csv(dataset.stations_path)
9999
stations.head()
100100

101101
###############################################################################

examples/0070_join_aggregation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,15 @@
8080
"""
8181

8282
# %%
83+
import pandas as pd
84+
8385
from skrub import TableReport
8486
from skrub.datasets import fetch_credit_fraud
8587

8688
bunch = fetch_credit_fraud()
87-
products, baskets = bunch.products, bunch.baskets
89+
products = pd.read_csv(bunch.products_path)
90+
baskets = pd.read_csv(bunch.baskets_path)
91+
8892
TableReport(products)
8993

9094
# %%
@@ -111,7 +115,6 @@
111115
# Then, we can expand all lists into columns, as if we were "flattening" the dataframe.
112116
# We end up with a products dataframe ready to be joined on the baskets dataframe, using
113117
# ``"basket_ID"`` as the join key.
114-
import pandas as pd
115118

116119
products_flatten = []
117120
for col in products_grouped.columns:

examples/0080_interpolation_join.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
from skrub.datasets import fetch_flight_delays
4141

4242
dataset = fetch_flight_delays()
43-
weather = dataset.weather
43+
weather = pd.read_csv(dataset.weather_path)
4444
weather = weather.sample(100_000, random_state=0, ignore_index=True)
45-
stations = dataset.stations
45+
stations = pd.read_csv(dataset.stations_path)
4646
weather = stations.merge(weather, on="ID")[
4747
["LATITUDE", "LONGITUDE", "YEAR/MONTH/DAY", "TMAX", "PRCP", "SNOW"]
4848
]
@@ -128,11 +128,13 @@
128128
# ``'Origin'`` which refers to the departure airport’s IATA code. We use only a subset
129129
# to speed up the example.
130130

131-
flights = dataset.flights
131+
flights = pd.read_csv(dataset.flights_path)
132132
flights["Year_Month_DayofMonth"] = pd.to_datetime(flights["Year_Month_DayofMonth"])
133133
flights = flights[["Year_Month_DayofMonth", "Origin", "ArrDelay"]]
134134
flights = flights.sample(20_000, random_state=0, ignore_index=True)
135-
airports = dataset.airports[["iata", "airport", "state", "lat", "long"]]
135+
airports = pd.read_csv(dataset.airports_path)[
136+
["iata", "airport", "state", "lat", "long"]
137+
]
136138
flights = flights.merge(airports, left_on="Origin", right_on="iata")
137139
# printing the first row is more readable than the head() when we have many columns
138140
flights.iloc[0]

0 commit comments

Comments
 (0)