Skip to main content

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.

Testing and linting codecov GitHub release (latest by date including pre-releases) PyPI

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

pdrepr-0.2.1.tar.gz (3.4 kB view hashes)

Uploaded source

Built Distribution

pdrepr-0.2.1-py3-none-any.whl (3.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page