Skip to content

Polars group by #648

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 6 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions polars-groupby/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This download contains materials for the Real Python tutorial [How to Group Data Using Polars .group_by()](https://realpython.com/aggregating-and-grouping-data-in-polars-groupby/).

You should create a new folder named aggregations on your computer and place each of these files inside it. You may also consider creating a [Python virtual environment](https://realpython.com/python-virtual-environments-a-primer/) within this folder.

Your download bundle contains the following files:

course.parquet - This file contains all data from both `math.parquet` and `portuguese.parquet`.
math.parquet - This file contains data relating to a mathematics class.
portuguese.parquet - This file contains data relating to a Portuguese language class.
student.txt - This file defines every field in the three files above.
math_classes.parquet - This file contains data used in the time series analysis examples.

tutorial_code.ipynb - This file contains the code used in the tutorial.
solutions.ipynb - This file contains the solutions to the exercises.
Binary file added polars-groupby/course.parquet
Binary file not shown.
Binary file added polars-groupby/math.parquet
Binary file not shown.
Binary file added polars-groupby/math_classes.parquet
Binary file not shown.
Binary file added polars-groupby/portuguese.parquet
Binary file not shown.
946 changes: 946 additions & 0 deletions polars-groupby/post_tr2.md

Large diffs are not rendered by default.

342 changes: 342 additions & 0 deletions polars-groupby/solutions.ipynb

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions polars-groupby/student.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Attributes for both student-mat.csv (Math course) and student-por.csv (Portuguese language course) datasets:
0 subject - subject (binary: "M" - Math or "P" - Portuguese language)
1 school - student's school (binary: "GP" - Gabriel Pereira or "MS" - Mousinho da Silveira)
2 sex - student's sex (binary: "F" - female or "M" - male)
3 age - student's age (numeric: from 15 to 22)
4 address - student's home address type (binary: "U" - urban or "R" - rural)
5 famsize - family size (binary: "LE3" - less or equal to 3 or "GT3" - greater than 3)
6 Pstatus - parent's cohabitation status (binary: "T" - living together or "A" - apart)
7 Medu - mother's education (numeric: 0 - none, 1 - primary education (4th grade), 2 – 5th to 9th grade, 3 – secondary education or 4 – higher education)
8 Fedu - father's education (numeric: 0 - none, 1 - primary education (4th grade), 2 – 5th to 9th grade, 3 – secondary education or 4 – higher education)
9 Mjob - mother's job (nominal: "teacher", "health" care related, civil "services" (e.g. administrative or police), "at_home" or "other")
10 Fjob - father's job (nominal: "teacher", "health" care related, civil "services" (e.g. administrative or police), "at_home" or "other")
11 reason - reason to choose this school (nominal: close to "home", school "reputation", "course" preference or "other")
12 guardian - student's guardian (nominal: "mother", "father" or "other")
13 traveltime - home to school travel time (numeric: 1 - <15 min., 2 - 15 to 30 min., 3 - 30 min. to 1 hour, or 4 - >1 hour)
14 studytime - weekly study time (numeric: 1 - <2 hours, 2 - 2 to 5 hours, 3 - 5 to 10 hours, or 4 - >10 hours)
15 failures - number of past class failures (numeric: n if 1<=n<3, else 4)
16 schoolsup - extra educational support (binary: yes or no)
17 famsup - family educational support (binary: yes or no)
18 paid - extra paid classes within the course subject (Math or Portuguese) (binary: yes or no)
19 activities - extra-curricular activities (binary: yes or no)
20 nursery - attended nursery school (binary: yes or no)
21 higher - wants to take higher education (binary: yes or no)
22 internet - Internet access at home (binary: yes or no)
23 romantic - with a romantic relationship (binary: yes or no)
24 famrel - quality of family relationships (numeric: from 1 - very bad to 5 - excellent)
25 freetime - free time after school (numeric: from 1 - very low to 5 - very high)
26 goout - going out with friends (numeric: from 1 - very low to 5 - very high)
27 Dalc - workday alcohol consumption (numeric: from 1 - very low to 5 - very high)
28 Walc - weekend alcohol consumption (numeric: from 1 - very low to 5 - very high)
29 health - current health status (numeric: from 1 - very bad to 5 - very good)
30 absences - number of school absences (numeric: from 0 to 93)

# these grades are related with the course subject, Math or Portuguese:
31 G1 - first period grade (numeric: from 0 to 20)
31 G2 - second period grade (numeric: from 0 to 20)
32 G3 - final grade (numeric: from 0 to 20, output target)

Additional note: there are several (382) students that belong to both datasets .
These students can be identified by searching for identical attributes
that characterize each student, as shown in the annexed R file.
Loading