Skip to content

Commit 66c2f3f

Browse files
committed
Restructure Pandas gradebook examples
1 parent e0190ed commit 66c2f3f

File tree

10 files changed

+30
-28
lines changed

10 files changed

+30
-28
lines changed

pandas-gradebook-project/loading-the-data/gradebook.py renamed to pandas-gradebook-project/01-loading-the-data.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
import pandas as pd
1313

1414
HERE = Path(__file__).parent
15-
DATA_FOLDER = HERE.parent / "data"
15+
DATA_FOLDER = HERE / "data"
1616

1717
roster = pd.read_csv(
1818
DATA_FOLDER / "roster.csv",
1919
converters={"NetID": str.lower, "Email Address": str.lower},
20+
usecols=["Section", "Email Address", "NetID"],
21+
index_col="NetID",
2022
)
23+
2124
# print(
22-
# roster.loc[
23-
# roster["ID"].isin([1234567, 2345678, 3456789, 4567890])
24-
# ].to_markdown()
25+
# roster.loc[["wxb12345", "mxl12345", "txj12345", "jgf12345"]].to_markdown()
2526
# )
2627

2728
hw_exam_grades = pd.read_csv(
2829
DATA_FOLDER / "hw_exam_grades.csv",
2930
converters={"SID": str.lower, "Email Address": str.lower},
3031
usecols=lambda x: "Submission" not in x,
32+
index_col="SID",
3133
)
3234
# print(
3335
# hw_exam_grades.loc[

pandas-gradebook-project/merging-dataframes/gradebook.py renamed to pandas-gradebook-project/02-merging-dataframes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pandas as pd
1313

1414
HERE = Path(__file__).parent
15-
DATA_FOLDER = HERE.parent / "data"
15+
DATA_FOLDER = HERE / "data"
1616

1717
roster = pd.read_csv(
1818
DATA_FOLDER / "roster.csv",

pandas-gradebook-project/calculating-grades/gradebook.py renamed to pandas-gradebook-project/03-calculating-grades.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import numpy as np
1414

1515
HERE = Path(__file__).parent
16-
DATA_FOLDER = HERE.parent / "data"
16+
DATA_FOLDER = HERE / "data"
1717

1818
roster = pd.read_csv(
1919
DATA_FOLDER / "roster.csv",
@@ -83,24 +83,24 @@
8383
# )
8484

8585
hw_max_renamed = homework_max_points.set_axis(homework_scores.columns, axis=1)
86-
overall_hw_scores = (homework_scores / hw_max_renamed).sum(axis=1)
87-
final_data["Overall Homework"] = overall_hw_scores / homework_scores.shape[1]
86+
average_hw_scores = (homework_scores / hw_max_renamed).sum(axis=1)
87+
final_data["Average Homework"] = average_hw_scores / homework_scores.shape[1]
8888

8989
# print(
90-
# pd.concat([overall_hw_scores, final_data["Overall Homework"]], axis=1)
91-
# .set_axis(["Sum of Overall Homework Scores", "Overall Homework"], axis=1)
90+
# pd.concat([average_hw_scores, final_data["Average Homework"]], axis=1)
91+
# .set_axis(["Sum of Average Homework Scores", "Average Homework"], axis=1)
9292
# .loc[["wxb12345", "mxl12345", "txj12345", "jgf12345"]]
9393
# .to_markdown()
9494
# )
9595

9696
final_data["Homework Score"] = final_data[
97-
["Total Homework", "Overall Homework"]
97+
["Total Homework", "Average Homework"]
9898
].max(axis=1)
9999

100100
# print(
101101
# final_data.loc[
102102
# ["wxb12345", "mxl12345", "txj12345", "jgf12345"],
103-
# ["Total Homework", "Overall Homework", "Homework Score"],
103+
# ["Total Homework", "Average Homework", "Homework Score"],
104104
# ].to_markdown()
105105
# )
106106

@@ -113,17 +113,17 @@
113113
sum_of_quiz_max = quiz_max_points.sum()
114114
final_data["Total Quizzes"] = sum_of_hw_scores / sum_of_hw_max
115115

116-
overall_quiz_scores = (quiz_scores / quiz_max_points).sum(axis=1)
117-
final_data["Overall Quizzes"] = overall_quiz_scores / quiz_scores.shape[1]
116+
average_quiz_scores = (quiz_scores / quiz_max_points).sum(axis=1)
117+
final_data["Average Quizzes"] = average_quiz_scores / quiz_scores.shape[1]
118118

119119
final_data["Quiz Score"] = final_data[
120-
["Total Quizzes", "Overall Quizzes"]
120+
["Total Quizzes", "Average Quizzes"]
121121
].max(axis=1)
122122

123123
# print(
124124
# final_data.loc[
125125
# ["wxb12345", "mxl12345", "txj12345", "jgf12345"],
126-
# ["Total Quizzes", "Overall Quizzes", "Quiz Score"],
126+
# ["Total Quizzes", "Average Quizzes", "Quiz Score"],
127127
# ].to_markdown()
128128
# )
129129

pandas-gradebook-project/grouping-the-data/gradebook.py renamed to pandas-gradebook-project/04-grouping-the-data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import numpy as np
1414

1515
HERE = Path(__file__).parent
16-
DATA_FOLDER = HERE.parent / "data"
16+
DATA_FOLDER = HERE / "data"
1717

1818
roster = pd.read_csv(
1919
DATA_FOLDER / "roster.csv",
@@ -126,5 +126,5 @@ def grade_mapping(value):
126126
for section, table in final_data.groupby("Section"):
127127
print(f"In Section {section} there are {table.shape[0]} students.")
128128
table.sort_values(by=["Last Name", "First Name"]).to_csv(
129-
DATA_FOLDER / "Section {section} Grades.csv"
129+
DATA_FOLDER / f"Section {section} Grades.csv"
130130
)

pandas-gradebook-project/gradebook.py renamed to pandas-gradebook-project/05-plotting-summary-statistics.py

File renamed without changes.

pandas-gradebook-project/plotting-summary-statistics/gradebook.py renamed to pandas-gradebook-project/06-final-gradebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import matplotlib.pyplot as plt
1515

1616
HERE = Path(__file__).parent
17-
DATA_FOLDER = HERE.parent / "data"
17+
DATA_FOLDER = HERE / "data"
1818

1919
roster = pd.read_csv(
2020
DATA_FOLDER / "roster.csv",

pandas-gradebook-project/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# Pandas Project: Make a Gradebook With Pandas
22

3-
The code in this folder is used to generate and process the data for the tutorial [_Pandas Project: Make a Gradebook With Pandas_](https://realpython.com/pandas-project-gradebook).
3+
The code in this folder is used to generate and process the data for the tutorial [Pandas Project: Make a Gradebook With Pandas_](https://realpython.com/pandas-project-gradebook).
44

55
## `generate_data.py`
66

77
The script `generate_data.py` uses the [Faker](https://faker.readthedocs.io/en/master/) library to generate fake student names and NumPy to generate scores for homework, exams, and quizzes. The data are stored as CSV files in the `data` folder. With the seed that is set in the script, the data used in the article can be reproduced. To try out new data, change the seed for the NumPy random number generator.
88

9-
## Folders with `gradebook.py` Scripts
9+
## Numbered Python Scripts
1010

11-
In the article, you create a script called `gradebook.py`. For didactic purposes, each of the steps in the development process is broken into a separate folder here. The `gradebook.py` scripts build from one folder to the next, to generate the final copy in the root directory here. The order in the article is:
11+
In the article, you create a script called `gradebook.py`. For didactic purposes, each of the steps in the development process is broken into a separate script here. The `.py` scripts build from one example to the next, to generate the final copy called `06-final-gradebook.py`. The order in the article is:
1212

13-
1. `loading-the-data`
14-
2. `merging-dataframes`
15-
3. `calculating-grades`
16-
4. `grouping-the-data`
17-
5. `plotting-summary-statistics`
13+
1. `01-loading-the-data.py`
14+
2. `02-merging-dataframes.py`
15+
3. `03-calculating-grades.py`
16+
4. `04-grouping-the-data.py`
17+
5. `05-plotting-summary-statistics.py`
1818

1919
## Installing Dependencies
2020

21-
There are two `requirements.txt`-style files in this repository. The `generate_data-reqs.txt` contains the dependencies for the `generate_data.py` script. The `gradebook-reqs.txt` file contains the dependencies for the `gradebook.py` script.
21+
There are two `requirements.txt` files in this repository. The `data/requirements.txt` contains the dependencies for the `generate_data.py` script. The `requirements.txt` file in the root folder contains the dependencies for the `gradebook.py` script.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)