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 profiling missing values #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A quick reference guide to the most commonly used patterns and functions in PySp
- [Filtering](#filtering)
- [Joins](#joins)
- [Column Operations](#column-operations)
- [Profiling Missing Values](#profiling-missing-values)
- [Casting & Coalescing Null Values & Duplicates](#casting--coalescing-null-values--duplicates)
- [String Operations](#string-operations)
- [String Filters](#string-filters)
Expand Down Expand Up @@ -109,6 +110,33 @@ for col in df.columns:
df = df.withColumnRenamed(col, col.lower().replace(' ', '_').replace('-', '_'))
```

#### Profiling Missing Values

```python
# count missing values in weight column
missing_weight= (
df.select(
F.count(F.when(F.col('weight').isNull() | F.isnan(F.col('weight')), ''))
.alias('missing_weight'))
)

# count missing values in all the columns (assuming they are all in numeric types such as: double, int, etc.)
missing_values= (
df.select([
F.count(F.when(F.col(c).isNull() | F.isnan(c), c))
.alias(c) for c in cols
])
)

# show rounded percentage of missing values
perc_missing_values= (
df.select([
F.round(F.count(F.when(F.isnan(c) | F.col(c).isNull(), c))/F.count(F.lit(1)), 2)
.alias(c) for c in cols
])
)
```

#### Casting & Coalescing Null Values & Duplicates

```python
Expand Down