{"id":16889746,"url":"https://github.com/jonashaag/pandas-memorytools","last_synced_at":"2026-05-20T06:02:11.936Z","repository":{"id":195255305,"uuid":"692576347","full_name":"jonashaag/pandas-memorytools","owner":"jonashaag","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-16T23:06:10.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T08:14:02.636Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonashaag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-09-16T22:58:18.000Z","updated_at":"2023-09-17T07:46:11.000Z","dependencies_parsed_at":"2023-09-17T07:16:17.083Z","dependency_job_id":null,"html_url":"https://github.com/jonashaag/pandas-memorytools","commit_stats":null,"previous_names":["jonashaag/pandas-memorytools"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashaag%2Fpandas-memorytools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashaag%2Fpandas-memorytools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashaag%2Fpandas-memorytools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashaag%2Fpandas-memorytools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonashaag","download_url":"https://codeload.github.com/jonashaag/pandas-memorytools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244571691,"owners_count":20474284,"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":[],"created_at":"2024-10-13T16:58:42.706Z","updated_at":"2026-05-20T06:02:11.830Z","avatar_url":"https://github.com/jonashaag.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pandas-memorytools\n\nA collection of tools to inspect and optimize Pandas memory usage.\n\n## Dtype recommender\n\npandas-memorytools can recommend smaller dtypes to reduce memory consumption of your dataframe with no loss of data.\n\nFor example, these are the recommendations for the [NYC Yello Taxi Trip Records](https://www.nyc.gov/site/tlc/about/tlc-trip-record-data.page):\n\n```py\n\u003e\u003e\u003e from pandas_memorytools import recommend_dtypes\n\u003e\u003e\u003e df_sample = df.sample(frac=0.01)\n\u003e\u003e\u003e recommend_dtypes(df_sample).sort_values(\"new_percent\")\n```\n\n| column                | original_dtype   | recommended_dtype   |   new_percent |   original_bytes |   new_bytes |\n|:----------------------|:-----------------|:--------------------|--------------:|-----------------:|------------:|\n| VendorID              | int64            | uint8               |         0.125 |          2453416 |      306677 |\n| payment_type          | int64            | uint8               |         0.125 |          2453416 |      306677 |\n| passenger_count       | float64          | UInt8               |         0.25  |          2453416 |      613354 |\n| RatecodeID            | float64          | UInt8               |         0.25  |          2453416 |      613354 |\n| PULocationID          | int64            | uint16              |         0.25  |          2453416 |      613354 |\n| DOLocationID          | int64            | uint16              |         0.25  |          2453416 |      613354 |\n| tpep_dropoff_datetime | datetime64[us]   | datetime64[us]      |         1     |          2453416 |     2453416 |\n| ...                   | ...              | ...                 |         ...   |              ... |         ... |\n\n## Memory consumption\n\npandas-memorytools features a more accurate effective memory consumption reporting than the following alternatives:\n\n- Pandas' `.memory_usage()`: Systematically overestimates the memory consumption of reused Python objects like small strings.\n  Does not support reporting memory usage of non-standard objects in columns, like lists.\n- `sys.getsizeof()`: Uses `.memory_usage()` under the hood, so has the same limitations as `.memory_usage()`.\n- Pympler: Similarly, systematically overestimates the memory consumption of reused Python objects like small strings.\n\nNote: Like Pandas' `.memory_usage()`, pandas-memorytools does not take into account the size of the `pd.DataFrame` and `pd.Series` objects (or any other non-data objects).\nIt assumes a size of 0 bytes for these objects. This is a simplifcation that is safe to make because for all relevant data sizes the size of these objects is negigible.\n\n\n### Comparison to Pandas\n\nHere is an example from the NYC Taxi dataset that shows the difference to Pandas' reporting:\n\n\n```py\n\u003e\u003e\u003e from pandas_memorytools import memory_usage\n\u003e\u003e\u003e df_sample[\"store_and_fwd_flag\"].memory_usage(deep=True)\n1999098\n\u003e\u003e\u003e memory_usage(df_sample[\"store_and_fwd_flag\"])\n245444\n```\n\nPandas' memory reporting is off by a factor of 8 because all Python strings in the column are cached:\n\n\n```py\n\u003e\u003e\u003e df[\"store_and_fwd_flag\"].unique()\narray(['N', 'Y', None], dtype=object)\n# Small strings and constants like 'None' are always cached by Python.\n```\n\nIf your string columns have a lot of Nones, the Pandas result will be off by a factor of 3:\n\n```py\n\u003e\u003e\u003e lots_of_nones = pd.Series([None] * 1_000_000)\n\u003e\u003e\u003e lots_of_nones.memory_usage(deep=True)\n24000132\n\u003e\u003e\u003e memory_usage(lots_of_nones)\n8000000\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashaag%2Fpandas-memorytools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonashaag%2Fpandas-memorytools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashaag%2Fpandas-memorytools/lists"}