Skip to main content

Pandas DataFrames / Pandas Series / Print colored Numpy arrays / lists / dicts / tuples!

Project description

Print colored Numpy arrays / pandas DataFrames / Pandas Series / lists / dicts / tuples!

pip install PrettyColorPrinter

This is everything you have to do to use PrettyColorPrinter with pandas

from PrettyColorPrinter import add_printer
add_printer() #This function will add some methods to PandasObject

#Let’s import pandas and create a DataFrame:

import pandas as pd
df=pd.read_csv(r"https://github.com/pandas-dev/pandas/raw/main/doc/data/air_quality_no2_long.csv")

Update 2022/12/27

You can switch between the colored version and the black/white version.

import pandas as pd
from PrettyColorPrinter import add_printer, switch_color_bw
add_printer(True)
switch_color_bw()

Update 2022/10/08

Fixed a bug with empty DataFrames

Update 2022/10/05

add_printer(overwrite_pandas_printer=False)
If you pass overwrite_pandas_printer=True then the color printer will replace __str__ and __repr__ from pandas

You can configure the color printer using:
     pd.color_printer_activate(print_stop:int=69,max_colwidth:int=300,repeat_cols:int=70)
     print_stop = maximum lines to print
     max_colwidth = maximum column width
     repeat_cols = for better readability, the columns are printed each x row


    This is how you switch back and forth between standard pandas and color printer:
      pd.color_printer_reset() #to standard pandas
      pd.color_printer_activate() #to color printer

Have a look

from PrettyColorPrinter import add_printer
from a_pandas_ex_plode_tool import pd_add_explode_tools
import pandas as pd
pd_add_explode_tools()
add_printer(overwrite_pandas_printer=True)
data={'critic_reviews': [{'review_critic': 'XYZ', 'review_score': 90},
                    {'review_critic': 'ABC', 'review_score': 90},
                    {'review_critic': '123', 'review_score': 90}],
 'genres': ['Sports', 'Golf'],
 'score': 85,
 'title': 'Golf Simulator',
 'url': 'http://example.com/golf-simulator'}
df = pd.Q_AnyNestedIterable_2df(data,unstack=False) #multiindex 
df2 = df.d_unstack() #normal index
df #if you type df, you will get a colored dataframe instead of the regular pandas version

All methods added to pandas start either with:

  • ds_ (for DataFrames and Series)

  • s_ (only for Series)

  • d_ (only for DataFrames)

All methods that are added to PandasObject

  • ds_color_print

  • ds_color_print_all

  • d_color_print_columns

  • d_color_print_index

  • ds_color_print_all_with_break

  • ds_color_print_context

#If you want to see some examples:
from PrettyColorPrinter import print_test_from_pandas_github
print_test_from_pandas_github()

#If you need help
help(df.ds_color_print)
qq_ds_print(max_rows: int = 1000, max_colwidth: int = 300, repeat_cols: int = 70, asnumpy: bool = False, returndf: bool = False) -> Union[pandas.core.frame.DataFrame, pandas.core.series.Series, NoneType] method of pandas.core.frame.DataFrame instance
    Parameters
    ----------
    df : pd.DataFrame, pd.Series
        Array to print
    max_rows : int
        Stop printing after n lines (default is 1000)
    max_colwidth : int
        Width of each column (default is 300)
    repeat_cols : int (default is 70)
        Print columns again after n lines  (default is 70)
    asnumpy: bool (default is False)
        Converts pandas DataFrame to np before printing.
        If there are duplicated columns in a Pandas DataFrame,
        it changes to printasnp = True  (default is False)
    returndf:  bool (default is False)
        return the input DataFrame to allow chaining

Using PrettyColorPrinter without pandas

**

The function pdp can be used without pandas. 
Doing it this way, you are not restricted to PandasObjects.

You can print lists, dicts, tuples, np.arrays, pd.DataFrames and pd.Series

**

from PrettyColorPrinter import pdp

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

PrettyColorPrinter-0.43.tar.gz (36.8 kB view details)

Uploaded Source

Built Distribution

PrettyColorPrinter-0.43-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

Details for the file PrettyColorPrinter-0.43.tar.gz.

File metadata

  • Download URL: PrettyColorPrinter-0.43.tar.gz
  • Upload date:
  • Size: 36.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for PrettyColorPrinter-0.43.tar.gz
Algorithm Hash digest
SHA256 2d9b83c3a7973e543c754ab2d2b787edb5d06d78469d37ef62eb68336926e7dd
MD5 5146b433cb10175925fbccb9c878c820
BLAKE2b-256 a07528f87fde059dfa5266c231aa0b217f270e5b9c15cd65e881d8430c9f8651

See more details on using hashes here.

File details

Details for the file PrettyColorPrinter-0.43-py3-none-any.whl.

File metadata

File hashes

Hashes for PrettyColorPrinter-0.43-py3-none-any.whl
Algorithm Hash digest
SHA256 7c0ec11e2f195cd4ed63ef83840d9d754addbd37985e8bc06d39a11d3559aa7d
MD5 ba9ae26435c4ce1d7c0d2b56ae6fe2cb
BLAKE2b-256 57801dee7194235a13f95ce77198968df32779edc89a4ebe2c282adcfc632e01

See more details on using hashes here.

Supported by

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