eval-able string representation of pandas objects
Project description
pdrepr
pdrepr takes a pandas DataFrame as input, and attempts to output a valid Python expression that will create an identical DataFrame. Supports multiindices for rows and columns, at least for the relatively
simple cases I have tested. DataFrames with datatypes other than strings, ints and floats should work if their
_repr__()
method also returns a string that can be passed to eval()
, resulting in a similar object.
Motivation
I was tired of having to manually construct DataFrames to be used in testing, especially the reference object to be compared with the resulting DF. With this package, such a code snipped can be created from the resulting DF.
Installation
Using poetry:
poetry add pdrepr
Using pipenv:
pipenv install pdrepr
Using pip:
pip install pdrepr
Usage
>>> from pdrepr import pdrepr
>>> pdrepr(df)
pd.DataFrame({'character': ['The Nude Organist', 'BBC continuity announcer', 'The Colonel'], 'played by': ['Terry Jones and Terry Gilliam', 'John Cleese', 'Graham Chapman']}).set_index(['character'])
>>> pd.DataFrame({'character': ['The Nude Organist', 'BBC continuity announcer', 'The Colonel'], 'played by': ['Terry Jones and Terry Gilliam', 'John Cleese', 'Graham Chapman']}).set_index(['character'])
played by
character
The Nude Organist Terry Jones and Terry Gilliam
BBC continuity announcer John Cleese
The Colonel Graham Chapman
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pdrepr-0.2.1.tar.gz
.
File metadata
- Download URL: pdrepr-0.2.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.0 Linux/5.13.0-1029-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 104cb246e40faaf4a7c9c5687234f2ab2e82ac47756514d1145184befca272e8 |
|
MD5 | 12b13ceadd9db0f1da92acbc9a54ff92 |
|
BLAKE2b-256 | 71f3f6754dd020608c15e8bc635dfbb9a3fac519ba9ed3ab61820432b2c5834f |
File details
Details for the file pdrepr-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: pdrepr-0.2.1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.10.0 Linux/5.13.0-1029-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47918c503527f75e022b0bf66eba64116bf0d6226d31d86ea3ff215e5bc57094 |
|
MD5 | 69358f76d3ae1bd46821d75a2207058a |
|
BLAKE2b-256 | c37b0a7d411352adbe66c97fb6ddb2b6d9f262e7a0629d5357a3a4f9a2bc2702 |