Skip to content

Commit df6b8e1

Browse files
committed
Post final QA
1 parent abc8109 commit df6b8e1

File tree

6 files changed

+36
-28
lines changed

6 files changed

+36
-28
lines changed
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
# How to Drop Null Values in pandas
2+
13
The materials contained in this download are designed to complement the Real Python tutorial [How to Drop Null Values in pandas](https://realpython.com/how-to-drop-null-values-in-pandas/).
24

3-
You should create a new folder named `pandas_nulls` on your computer and place each file inside it. You may also consider creating a [Python virtual environment](https://realpython.com/python-virtual-environments-a-primer/) within this folder.
5+
Consider creating a [Python virtual environment](https://realpython.com/python-virtual-environments-a-primer/) before installing the dependencies:
6+
7+
```shell
8+
$ python3 -m venv .venv/ --prompt pandas-nulls
9+
$ source .venv/bin/activate
10+
(pandas-nulls) $ python -m pip install -r requirements.txt
11+
```
12+
13+
Your download bundle contains the following four files:
414

5-
Your download bundle contains the following four files. The first three files contain the code from different tutorial sections, while the fourth contains the solutions to the exercise.
15+
1. `drop_null_rows.py`
16+
2. `drop_null_columns.py`
17+
3. `drop_a_subset.py`
18+
4. `exercise_solutions.py`
619

7-
`drop_null_rows.py`
8-
`drop_null_columns.py`
9-
`drop_a_subset.py`
10-
`exercise_solutions.py`
20+
The first three files contain the code from different tutorial sections, while the fourth contains the solutions to the exercise.
1121

1222
There are also two data files containing the data used throughout the tutorial:
1323

14-
`sales_data_with_missing_values.csv`
15-
`grades.csv`
24+
1. `sales_data_with_missing_values.csv`
25+
2. `grades.csv`

how-to-drop-null-values-in-pandas/drop_a_subset.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88
date_format="%d/%m/%Y",
99
).convert_dtypes(dtype_backend="pyarrow")
1010

11-
12-
sales_data.dropna(axis=0, subset=(["discount", "sale_price"]))
13-
14-
sales_data.dropna(how="all")
15-
16-
sales_data.dropna(thresh=5)
17-
18-
sales_data.dropna(thresh=5, ignore_index=True)
11+
print(sales_data.dropna(axis=0, subset=(["discount", "sale_price"])))
12+
print(sales_data.dropna(how="all"))
13+
print(sales_data.dropna(thresh=5))
14+
print(sales_data.dropna(thresh=5, ignore_index=True))

how-to-drop-null-values-in-pandas/drop_null_columns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
date_format="%d/%m/%Y",
77
).convert_dtypes(dtype_backend="pyarrow")
88

9-
sales_data.dropna(axis="columns")
9+
print(sales_data.dropna(axis="columns"))

how-to-drop-null-values-in-pandas/drop_null_rows.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
date_format="%d/%m/%Y",
99
).convert_dtypes(dtype_backend="pyarrow")
1010

11-
sales_data
12-
13-
sales_data.isna().sum()
14-
15-
sales_data.dropna()
11+
print(sales_data)
12+
print(sales_data.isna().sum())
13+
print(sales_data.dropna())
1614

1715
clean_sales_data = sales_data.dropna()
16+
print(clean_sales_data)
1817

19-
clean_sales_data = sales_data.dropna(inplace=True)
18+
sales_data.dropna(inplace=True)
19+
print(sales_data)

how-to-drop-null-values-in-pandas/exercise_solutions.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,16 @@
55
).convert_dtypes(dtype_backend="pyarrow")
66

77
# 1. Use `.dropna()` in such a way that it permanently drops the row in the dataframe containing only null values.
8-
98
grades.dropna(how="all", inplace=True)
109

1110
# 2. Display the rows for the exams that all students have completed.
12-
1311
grades.dropna()
1412

1513
# 3. Display any columns with no missing data.
16-
1714
grades.dropna(axis=1)
1815

1916
# 4. Display the exams sat by at least five students.
20-
2117
grades.dropna(axis=0, thresh=6) # Remember there are seven columns.
2218

2319
# 5. Who else was in in every exam that both S2 and S4 sat?
24-
2520
grades.dropna(subset=["S2", "S4"]).dropna(axis=1, ignore_index=True)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
numpy==2.3.2
2+
pandas==2.3.2
3+
pyarrow==21.0.0
4+
python-dateutil==2.9.0.post0
5+
pytz==2025.2
6+
six==1.17.0
7+
tzdata==2025.2

0 commit comments

Comments
 (0)