{"id":28470314,"url":"https://github.com/lucianosrp/dapter","last_synced_at":"2025-07-01T17:31:31.780Z","repository":{"id":252844908,"uuid":"841296117","full_name":"lucianosrp/dapter","owner":"lucianosrp","description":"Tool to adapt multiple dataframes to one unique format","archived":false,"fork":false,"pushed_at":"2024-08-17T10:10:20.000Z","size":26,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-07T09:11:27.105Z","etag":null,"topics":["data-science","dataframe","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucianosrp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-12T05:55:23.000Z","updated_at":"2024-08-22T20:21:17.000Z","dependencies_parsed_at":"2024-08-16T22:24:27.469Z","dependency_job_id":"b0e9c365-5322-4a79-a45a-1ed807645cd3","html_url":"https://github.com/lucianosrp/dapter","commit_stats":null,"previous_names":["lucianosrp/dapter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/lucianosrp/dapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucianosrp%2Fdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucianosrp%2Fdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucianosrp%2Fdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucianosrp%2Fdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucianosrp","download_url":"https://codeload.github.com/lucianosrp/dapter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucianosrp%2Fdapter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263007187,"owners_count":23398776,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science","dataframe","python"],"created_at":"2025-06-07T09:10:36.754Z","updated_at":"2025-07-01T17:31:31.771Z","avatar_url":"https://github.com/lucianosrp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"docs/assets/dapter-light.svg\"\u003e\n  \u003cimg src=\"docs/assets/dapter-dark.svg\"  width=\"300\"\u003e\n\u003c/picture\u003e\n\n\n\u003e Data + Adapter \n\nDapter is a convenient tool that helps working with multiple data sources. It allows you to easily rename column names and transform your data in one go.\n\nWith Dapter, you can store a series of instructions for your data cleaning routines into custom objects. You can then reuse the object to any DataFrames at any part of your code. See the step-by-step example below.\n\n\n## 📝 Example\n\nRenaming columns and adding transformations can be \"lazily\" set-up in a tuple:\n\n```python\nimport pandas as pd\nfrom dapter import accepts\n\ndef convert_to_eur(col: pd.Series) -\u003e pd.Series:\n    return col * 0.92\n\neur_col = (accepts(\"Amount USD\", \"amount_usd\",\"USD\"), convert_to_eur)\n```\n\n`euro_col` is a series of instructions that will tell `dapter` to:\n- Consider any column that is named after one of the names in `accepts`\n- Apply `convert_to_eur` to those columns\n\nOnce we have defined all the column _\"instructions\"_ we can then store them together in a custom object that inherits from `dapter.BaseMapper`\n\n```python\nfrom dapter import BaseMapper\n\nclass TransactionMapper(BaseMapper):\n    amount_eur = euro_col\n```\n\nWe have just defined that all instructions of `euro_col` will be assigned to a new column called `amount_eur`.\n\nThis object can then be used to apply all the renaming and transformations stored inside it to any `DataFrame`\n\n```python\nmapper = TransactionMapper()\n\ndfs = mapper.apply(df1, df2, df3)\ndf = pd.concat(dfs)\n```\n## 🧰 Installation\n\nUsing pip:\n\n```\npip install dapter\n```\n\n## 🔄 Infinite DataFrame compatibility\n\nDapter uses [narwhals](https://narwhals-dev.github.io/narwhals/) in the background so it can accepts any (See supported[^1]) kind of DataFrame libraries.\n\nWhich means you can define Polars `Series` and `Expr` transformations for pandas' `Series` and vice-versa! \n\nYou can also feed any DataFrame to the `apply` method.\n\n\n[^1]:  cuDF, Modin, pandas, Polars, PyArrow, Dask, Ibis, Vaex\n\n## Full sample code \n\n```python\nfrom dapter import BaseMapper, accepts, accepts_anycases\nimport pandas as pd\n\ndf1 = pd.DataFrame(\n    [\n        {\n            \"Date\": \"2023-02-01 10:00:01\",\n            \"Vendor Name\": \"Golden Oil LLC\",\n            \"Amount USD\": 49.99,\n            \"Category\": \"Personal\",\n        }\n    ]\n)\n\ndf2 = pd.DataFrame(\n    [\n        {\n            \"transaction_date\": \"2023-03-01 10:00:01\",\n            \"vendor_name\": \"Get Cars Inc.\",\n            \"amount_usd\": 2999.9,\n            \"category\": \"Transportation\",\n        }\n    ]\n)\ndf3 = pd.DataFrame(\n    [\n        {\n            \"DATE\": \"2023-04-01 10:00:01\",\n            \"VENDOR_NAME\": \"Maintainers Exc.\",\n            \"USD\": 5249.0,\n            \"CAT\": \"Personal\",\n        }\n    ]\n)\n\n\ndef convert_to_eur(col: pd.Series) -\u003e pd.Series:\n    return col * 0.92\n\ndef clean_str(col:pd.Series) -\u003e pd.Series:\n    return col.str.to_lower().str.replace(\" \",\"_\")\n\nclass TransactionMapper(BaseMapper):\n    transaction_date = accepts(\"transaction_date\", \"Date\",\"DATE\")\n    vendor_name = accepts_anycases()    \n    amount_eur = accepts(\"Amount USD\", \"amount_usd\",\"USD\"), convert_to_eur\n    category = accepts(\"Category\", \"category\",\"CAT\"), clean_str\n\nmapper = TransactionMapper()\n\ndfs = mapper.apply(df1, df2, df3)\ndf = pd.concat(dfs)\ndf\n```\n\n| transaction_date | vendor_name | amount_eur | category |\n|------|--------|------------|---------|\n2023-02-01 10:00:01| Golden Oil LLC | 45.99  |  personal \n2023-03-01 10:00:01| Get Cars Inc. | 2999.9  |  transportation \n2023-04-01 10:00:01| Maintainers Exc. | 5249.0  |  personal ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucianosrp%2Fdapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucianosrp%2Fdapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucianosrp%2Fdapter/lists"}