Each row represents a country on a given year. https://www.gapminder.org/data/ Parameters ---------- datetimes: bool Whether or not 'year' column will converted to datetime type centroids: bool If True, ['centroid_lat', 'centroid_lon'] columns are added
(
datetimes=False,
centroids=False,
year=None,
pretty_names=False,
return_type="pandas",
)
| 12 | |
| 13 | |
| 14 | def gapminder( |
| 15 | datetimes=False, |
| 16 | centroids=False, |
| 17 | year=None, |
| 18 | pretty_names=False, |
| 19 | return_type="pandas", |
| 20 | ): |
| 21 | """ |
| 22 | Each row represents a country on a given year. |
| 23 | |
| 24 | https://www.gapminder.org/data/ |
| 25 | |
| 26 | Parameters |
| 27 | ---------- |
| 28 | datetimes: bool |
| 29 | Whether or not 'year' column will converted to datetime type |
| 30 | |
| 31 | centroids: bool |
| 32 | If True, ['centroid_lat', 'centroid_lon'] columns are added |
| 33 | |
| 34 | year: int | None |
| 35 | If provided, the dataset will be filtered for that year |
| 36 | |
| 37 | pretty_names: bool |
| 38 | If True, prettifies the column names |
| 39 | |
| 40 | return_type: {'pandas', 'polars', 'pyarrow', 'modin', 'cudf'} |
| 41 | Type of the resulting dataframe |
| 42 | |
| 43 | Returns |
| 44 | ------- |
| 45 | Dataframe of `return_type` type |
| 46 | Dataframe with 1704 rows and the following columns: |
| 47 | `['country', 'continent', 'year', 'lifeExp', 'pop', 'gdpPercap', |
| 48 | 'iso_alpha', 'iso_num']`. |
| 49 | |
| 50 | If `datetimes` is True, the 'year' column will be a datetime column |
| 51 | If `centroids` is True, two new columns are added: ['centroid_lat', 'centroid_lon'] |
| 52 | If `year` is an integer, the dataset will be filtered for that year |
| 53 | """ |
| 54 | df = nw.from_native( |
| 55 | _get_dataset("gapminder", return_type=return_type), eager_only=True |
| 56 | ) |
| 57 | if year: |
| 58 | df = df.filter(nw.col("year") == year) |
| 59 | if datetimes: |
| 60 | df = df.with_columns( |
| 61 | # Concatenate the year value with the literal "-01-01" so that it can be |
| 62 | # casted to datetime from "%Y-%m-%d" format |
| 63 | nw.concat_str( |
| 64 | [nw.col("year").cast(nw.String()), nw.lit("-01-01")] |
| 65 | ).str.to_datetime(format="%Y-%m-%d") |
| 66 | ) |
| 67 | if not centroids: |
| 68 | df = df.drop("centroid_lat", "centroid_lon") |
| 69 | if pretty_names: |
| 70 | df = df.rename( |
| 71 | dict( |
nothing calls this directly
no test coverage detected