Skip to main content

Takes a pandas dataframe and returns more-narrow narrow markdown string suitable for printing in a Jupyter notebook.

Project description

pandasfruit

Summary

Takes in a pandas dataframe and returns a string containing markdown format where the width of the markdown text is more narrow and is suitable for printing. The more narrow table can fit on a printed page, such as a PDF generated from a Jupyter notebook.

Takes in an optional width parameter (number of characters) and will make the resulting markdown this wide. Else will use a default width of 115.

Also will use a default dictionary of words/abbreviations to shorten column names using the abbreviations instead of the original words. Alternatively, a user-defined dictionary may be passed in. Pass in empty dictionary to do no replacements.

Processing

To achieve the more-narrow markdown version of the df, first column names are shortened using the default abbreviations dictionary (or the optional user-provided dictionary). Keywords in column names are replaced with abbreviations. Note that column names may contain words separated by either underscores or spaces.

If, after wrapping column names, the width of the markdown is still greater than the desired markdown width, the columns are iteratively wrapped to increasingly shorter widths until the desired width of the markdown is achieved.

Installation

pip install pandasfruit

Usage

import pandas as pd
from pandasfruit import pandasfruit
x = pd.DataFrame(
    {
        'c foobar person number clean': [
            '00000001',
            '00000002',
            '00000003',
            '00000004',
            '00000005',
            '00000006',
            '00000007',
            '00000008'
        ],
        
        'c foobar first name clean': [
            'Eduard',
            'Andriel',
            'Faris',
            'Shaye',
            'Rodney',
            'Arledge',
            'Cory',
            'Madison'
        ],
        
        'c foobar last name clean': [
            'Davis',
            'Bell',
            'Russell',
            'Fisher',
            'Wilson',
            'Campbell',
            'Collins',
            'Thomas'
        ],
        
        'c _foobar_home_street_address_1_clean': [
        
            '1234 Maple Street REALLY REALLY REALLY SUPER REAL LONG '
            'STREET MORE MORE MORE WORDS SOME MORE',
            '5678 Oakwood Avenue',
            '910 Willow Lane',
            '1122 Elm Drive',
            '1314 Cedar Boulevard',
            '1516 Pine Court',
            '1718 Birch Road',
            '1920 Juniper Place REALLY REALLY REALLY SUPER DUPER LONG '
            'APARTMENT NAME EVEN MORE WORDS HERE OK SOME MORE'
        ],

        'c foobar home street address 2 clean': [
            'Apartment 200',
            'Suite 6 MORE MORE MORE AND EVEN MORE WORDS AND ADDING SOME '
            'MORE WORDS AND HERE ARE EVEN SOME MORE AND EVEN MORE WORDS '
            'ARE ADDED HERE OK',
            'Apt. 2',
            'Apartment 4021',
            '2nd Floor',
            'Unit C',
            'Apt. 3',
            'Downstairs'
        ]
    }
)
print(x.to_markdown(tablefmt='grid'))

x_for_display = pandasfruit.df_to_fitted_markdown(x)

print(x_for_display)

x_for_display = pandasfruit.df_to_fitted_markdown(x, width=80, abbreviations={'foo_bar': 'fb', 'baz ham': 'baz h'})

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

pandasfruit-1.4.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pandasfruit-1.4.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pandasfruit-1.4.1.tar.gz.

File metadata

  • Download URL: pandasfruit-1.4.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pandasfruit-1.4.1.tar.gz
Algorithm Hash digest
SHA256 679662cf6d339f9bb530628370903461e8ecfb8d27eda1bad6447980924c2782
MD5 6835765b492715669da14b2db8e38b9c
BLAKE2b-256 4a9672dde5043ac28c4d607ae5cee8cd448da3b7d9fd9d960c418fb5cb38b68e

See more details on using hashes here.

File details

Details for the file pandasfruit-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: pandasfruit-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for pandasfruit-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c3b0d8cf6ff1dc34ded6ff468c96759efa4a98c5c0f5cd44ac531f60e81429f
MD5 a85e388c763bc9aca55bec4babca9b68
BLAKE2b-256 5c90e684a525c4969cce28b13180d372b71c0a8debb9b19df2f9886161fdfa64

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page