forked from im-anishraj/arnio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
61 lines (49 loc) · 1.7 KB
/
Copy pathbasic_usage.py
File metadata and controls
61 lines (49 loc) · 1.7 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Basic Usage Example for Arnio
-----------------------------
This script demonstrates the core functionality of Arnio:
reading a CSV file, defining a cleaning pipeline, and converting the result
to a pandas DataFrame.
"""
import os
import arnio as ar
def main():
# 1. Create a sample CSV file
sample_csv = "sample_messy_data.csv"
with open(sample_csv, "w") as f:
f.write("name,age,city\n")
f.write(" Alice ,30,New York\n")
f.write("Bob,,\n") # Missing age and city
f.write("Charlie,35, London \n")
f.write("Alice,30,New York\n") # Duplicate
print(f"Created sample file: {sample_csv}")
# 2. Load the raw file using the C++ core
frame = ar.read_csv(sample_csv)
print("\n--- Raw Data Schema ---")
print(frame.dtypes)
# 3. Profile the data quality before cleaning
report = ar.profile(frame)
print("\n--- Data Quality Report ---")
print(f"Rows: {report.row_count}, Columns: {report.column_count}")
print(f"Duplicates: {report.duplicate_rows}")
if report.suggestions:
print(f"Suggested steps: {report.suggestions}")
# 4. Define a strict, readable cleaning pipeline
clean_frame = ar.pipeline(
frame,
[
("strip_whitespace",),
("normalize_case", {"case_type": "title"}),
("fill_nulls", {"value": 0, "subset": ["age"]}),
("fill_nulls", {"value": "Unknown", "subset": ["city"]}),
("drop_duplicates",),
],
)
# 5. Export to a clean pandas DataFrame
df = ar.to_pandas(clean_frame)
print("\n--- Cleaned Pandas DataFrame ---")
print(df)
# Cleanup
os.remove(sample_csv)
if __name__ == "__main__":
main()