-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
43 lines (36 loc) · 951 Bytes
/
script.py
File metadata and controls
43 lines (36 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python3
# /// script
# dependencies = ["click", "polars"]
# ///
import click
import polars as pl
COLUMNS = [
"election_lbl",
"election_desc",
"voting_method",
"voted_party_cd",
"voted_party_desc",
]
@click.command()
@click.argument("filepath", default="scratch/data/ncvhis_Statewide.txt")
def main(filepath):
"""Find unique values for key columns in the NC voter history file."""
click.echo(f"Scanning {filepath} ...")
unique_values = (
pl.scan_csv(
filepath,
separator="\t",
quote_char='"',
infer_schema=False,
)
.select(COLUMNS)
.unique()
.collect()
)
for col in COLUMNS:
values = sorted(unique_values[col].drop_nulls().unique().to_list())
click.echo(f"\n{col} ({len(values)} unique):")
for v in values:
click.echo(f" {v}")
if __name__ == "__main__":
main()