Skip to content
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

Add survey demo dataset #313

Merged
merged 6 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
25 changes: 20 additions & 5 deletions metasyn/demo/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def demo_file(name: str = "titanic") -> Path:
- titanic (Included in pandas, but post-processed to contain more columns)
vankesteren marked this conversation as resolved.
Show resolved Hide resolved
- spaceship (CC-BY from https://www.kaggle.com/competitions/spaceship-titanic)
- fruit (very basic example data from Polars)

- survey (columns from ESS round 11 Human Values Scale questionnaire for the Netherlands)
Arguments
---------
name:
Expand All @@ -85,16 +85,24 @@ def demo_file(name: str = "titanic") -> Path:
-------
Path to the dataset.

References
----------
European Social Survey European Research Infrastructure (ESS ERIC). (2024). ESS11 integrated
file, edition 1.0 [Data set]. Sikt - Norwegian Agency for Shared Services in Education and
Research. https://doi.org/10.21338/ess11e01_0

"""
if name == "titanic":
return files(__package__) / "demo_titanic.csv"
if name == "spaceship":
return files(__package__) / "demo_spaceship.csv"
if name == "fruit":
return files(__package__) / "demo_fruit.csv"
if name == "survey":
return files(__package__) / "demo_survey.csv"

raise ValueError(
f"No demonstration dataset with name '{name}'. Options: titanic, spaceship, fruit."
f"No demonstration dataset with name '{name}'. Options: titanic, spaceship, fruit, survey."
)


Expand All @@ -105,6 +113,7 @@ def demo_dataframe(name: str = "titanic") -> pl.DataFrame:
- titanic (Included in pandas, but post-processed to contain more columns)
vankesteren marked this conversation as resolved.
Show resolved Hide resolved
- spaceship (CC-BY from https://www.kaggle.com/competitions/spaceship-titanic)
- fruit (very basic example data from Polars)
- survey (columns from ESS round 11 Human Values Scale questionnaire for the Netherlands)

Arguments
---------
Expand All @@ -115,6 +124,12 @@ def demo_dataframe(name: str = "titanic") -> pl.DataFrame:
-------
Polars dataframe with correct column types

References
----------
European Social Survey European Research Infrastructure (ESS ERIC). (2024). ESS11 integrated
file, edition 1.0 [Data set]. Sikt - Norwegian Agency for Shared Services in Education and
Research. https://doi.org/10.21338/ess11e01_0

"""
file_path = demo_file(name=name)
if name == "spaceship":
Expand All @@ -126,9 +141,7 @@ def demo_dataframe(name: str = "titanic") -> pl.DataFrame:
"Destination": pl.Categorical,
"Transported": pl.Categorical,
}
return pl.read_csv(
file_path, schema_overrides=data_types, try_parse_dates=True
)
return pl.read_csv(file_path, schema_overrides=data_types, try_parse_dates=True)
if name == "titanic":
# our edited titanic data
data_types = {"Sex": pl.Categorical, "Embarked": pl.Categorical}
Expand All @@ -137,6 +150,8 @@ def demo_dataframe(name: str = "titanic") -> pl.DataFrame:
# basic fruit data from polars example
data_types = {"fruits": pl.Categorical, "cars": pl.Categorical}
return pl.read_csv(file_path, schema_overrides=data_types)
if name == "survey":
return pl.read_csv(file_path)

raise ValueError(
f"No demonstration dataset with name '{name}'. Options: titanic, spaceship, fruit."
Expand Down
Loading
Loading