-
Notifications
You must be signed in to change notification settings - Fork 11
docs: add PyJanitor interoperability example #179
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
Merged
JohnnyWilson16
merged 2 commits into
FreshCode-Org:main
from
WilliamK112:agent/pyjanitor-interop
Aug 14, 2026
+114
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| """Use FreshData and PyJanitor in the same pandas workflow. | ||
|
|
||
| PyJanitor is optional; install it alongside FreshData to run this example: | ||
|
|
||
| pip install freshdata-cleaner "pyjanitor<0.32" | ||
|
|
||
| FreshData 2.0 supports pandas 1.5–2.x; PyJanitor 0.31 is the compatible line | ||
| verified for this example. | ||
|
|
||
| Use PyJanitor for explicit DataFrame reshaping and method-style transforms. | ||
| Use FreshData for evidence-based quality detection, conservative repair, and | ||
| an audit report. Either tool can go first, depending on which step needs the | ||
| other tool's output. | ||
| """ | ||
|
|
||
| import pandas as pd | ||
| from janitor import clean_names, transform_column # type: ignore[import-untyped] | ||
|
|
||
| import freshdata as fd | ||
|
|
||
|
|
||
| def build_frame() -> pd.DataFrame: | ||
| """Return one small frame used by both ordering examples.""" | ||
| return pd.DataFrame( | ||
| { | ||
| " Customer ID ": ["C-01", "C-02", "C-03", "C-03"], | ||
| "Order Amount": ["12.50", "n/a", "18.00", "18.00"], | ||
| "Region Name": [" North ", "south", "NORTH", "NORTH"], | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def pyjanitor_then_freshdata(raw: pd.DataFrame) -> tuple[pd.DataFrame, fd.CleanReport]: | ||
| """Shape labels explicitly, then detect and repair quality issues.""" | ||
| shaped = clean_names(raw, remove_special=True, strip_underscores="both") | ||
| return fd.clean( | ||
| shaped, | ||
| id_columns=("customer_id",), | ||
| return_report=True, | ||
| ) | ||
|
|
||
|
|
||
| def freshdata_then_pyjanitor(raw: pd.DataFrame) -> tuple[pd.DataFrame, fd.CleanReport]: | ||
| """Repair with an audit trail, then add an explicit presentation column.""" | ||
| cleaned, report = fd.clean( | ||
| raw, | ||
| id_columns=("customer_id",), | ||
| return_report=True, | ||
| ) | ||
| enriched = transform_column( | ||
| cleaned, | ||
| column_name="region_name", | ||
| function=lambda value: value.strip().title(), | ||
| dest_column_name="region_label", | ||
| ) | ||
| return enriched, report | ||
|
|
||
|
|
||
| def main() -> None: | ||
| raw = build_frame() | ||
|
|
||
| cleaned, clean_report = pyjanitor_then_freshdata(raw) | ||
| print("=== PyJanitor then FreshData ===") | ||
| print(cleaned) | ||
| print(clean_report.summary()) | ||
|
|
||
| enriched, enriched_report = freshdata_then_pyjanitor(raw) | ||
| print("\n=== FreshData then PyJanitor ===") | ||
| print(enriched) | ||
| print(enriched_report.summary()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.