PrettyColorPrinter


NamePrettyColorPrinter JSON
Version 0.45 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/PrettyColorPrinter
SummaryPandas DataFrames / Pandas Series / Print colored Numpy arrays / lists / dicts / tuples!
upload_time2024-02-23 00:04:14
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords pandas numpy dataframe series print prettyprint colored coloured
VCS
bugtrack_url
requirements cprinter input_timeout keyboard kthread numpy pandas regex
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# **Print colored Numpy arrays / pandas DataFrames / Pandas Series / lists / dicts / tuples!**

```python
pip install PrettyColorPrinter
```

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

```python
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. 

```python
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**

```python
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

```python
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
```

![](https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a12.png)

![](https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a13.png)

<img title="" src="https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a11.png" alt="">

**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**

```python
#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**

**

```python
from PrettyColorPrinter import pdp
```

<img title="" src="https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a1.png" alt="">
<img title="" src="https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a2.png" alt="">
<img title="" src="https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a3.png" alt="">
<img title="" src="https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a5.png" alt="">

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/PrettyColorPrinter",
    "name": "PrettyColorPrinter",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "pandas,numpy,dataframe,series,print,prettyprint,colored,coloured",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/31/30/bdaedb739af1c980792ecfeaf90337034786af8656320e6ee49884d78af0/PrettyColorPrinter-0.45.tar.gz",
    "platform": null,
    "description": "\r\n# **Print colored Numpy arrays / pandas DataFrames / Pandas Series / lists / dicts / tuples!**\r\n\r\n```python\r\npip install PrettyColorPrinter\r\n```\r\n\r\n#### **This is everything you have to do to use PrettyColorPrinter with pandas**\r\n\r\n```python\r\nfrom PrettyColorPrinter import add_printer\r\nadd_printer() #This function will add some methods to PandasObject\r\n\r\n#Let\u2019s import pandas and create a DataFrame:\r\n\r\nimport pandas as pd\r\ndf=pd.read_csv(r\"https://github.com/pandas-dev/pandas/raw/main/doc/data/air_quality_no2_long.csv\")\r\n```\r\n\r\n### Update 2022/12/27\r\n\r\nYou can switch between the colored version and the black/white version. \r\n\r\n```python\r\nimport pandas as pd\r\nfrom PrettyColorPrinter import add_printer, switch_color_bw\r\nadd_printer(True)\r\nswitch_color_bw()\r\n\r\n```\r\n\r\n### Update 2022/10/08\r\n\r\nFixed a bug with empty DataFrames\r\n\r\n### **Update 2022/10/05**\r\n\r\n```python\r\nadd_printer(overwrite_pandas_printer=False)\r\nIf you pass overwrite_pandas_printer=True then the color printer will replace __str__ and __repr__ from pandas\r\n\r\nYou can configure the color printer using:\r\n     pd.color_printer_activate(print_stop:int=69,max_colwidth:int=300,repeat_cols:int=70)\r\n     print_stop = maximum lines to print\r\n     max_colwidth = maximum column width\r\n     repeat_cols = for better readability, the columns are printed each x row\r\n\r\n\r\n    This is how you switch back and forth between standard pandas and color printer:\r\n      pd.color_printer_reset() #to standard pandas\r\n      pd.color_printer_activate() #to color printer\r\n```\r\n\r\n### Have a look\r\n\r\n```python\r\nfrom PrettyColorPrinter import add_printer\r\nfrom a_pandas_ex_plode_tool import pd_add_explode_tools\r\nimport pandas as pd\r\npd_add_explode_tools()\r\nadd_printer(overwrite_pandas_printer=True)\r\ndata={'critic_reviews': [{'review_critic': 'XYZ', 'review_score': 90},\r\n                    {'review_critic': 'ABC', 'review_score': 90},\r\n                    {'review_critic': '123', 'review_score': 90}],\r\n 'genres': ['Sports', 'Golf'],\r\n 'score': 85,\r\n 'title': 'Golf Simulator',\r\n 'url': 'http://example.com/golf-simulator'}\r\ndf = pd.Q_AnyNestedIterable_2df(data,unstack=False) #multiindex \r\ndf2 = df.d_unstack() #normal index\r\ndf #if you type df, you will get a colored dataframe instead of the regular pandas version\r\n```\r\n\r\n![](https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a12.png)\r\n\r\n![](https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a13.png)\r\n\r\n<img title=\"\" src=\"https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a11.png\" alt=\"\">\r\n\r\n**All methods added to pandas start either with:**\r\n\r\n- **ds_** (for DataFrames and Series)\r\n\r\n- **s_** (only for Series) \r\n\r\n- **d_** (only for DataFrames)\r\n\r\n### **All methods that are added to PandasObject**\r\n\r\n- **ds_color_print**\r\n\r\n- **ds_color_print_all**\r\n\r\n- **d_color_print_columns**\r\n\r\n- **d_color_print_index**\r\n\r\n- **ds_color_print_all_with_break**\r\n\r\n- **ds_color_print_context**\r\n\r\n```python\r\n#If you want to see some examples:\r\nfrom PrettyColorPrinter import print_test_from_pandas_github\r\nprint_test_from_pandas_github()\r\n\r\n#If you need help\r\nhelp(df.ds_color_print)\r\nqq_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\r\n    Parameters\r\n    ----------\r\n    df : pd.DataFrame, pd.Series\r\n        Array to print\r\n    max_rows : int\r\n        Stop printing after n lines (default is 1000)\r\n    max_colwidth : int\r\n        Width of each column (default is 300)\r\n    repeat_cols : int (default is 70)\r\n        Print columns again after n lines  (default is 70)\r\n    asnumpy: bool (default is False)\r\n        Converts pandas DataFrame to np before printing.\r\n        If there are duplicated columns in a Pandas DataFrame,\r\n        it changes to printasnp = True  (default is False)\r\n    returndf:  bool (default is False)\r\n        return the input DataFrame to allow chaining\r\n```\r\n\r\n### Using PrettyColorPrinter without pandas\r\n\r\n**\r\n\r\nThe function **pdp** can be used without pandas.\u00a0  \r\nDoing it this way, you are not restricted to PandasObjects.\r\n\r\n**You can print lists, dicts, tuples, np.arrays, pd.DataFrames and pd.Series**\r\n\r\n**\r\n\r\n```python\r\nfrom PrettyColorPrinter import pdp\r\n```\r\n\r\n<img title=\"\" src=\"https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a1.png\" alt=\"\">\r\n<img title=\"\" src=\"https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a2.png\" alt=\"\">\r\n<img title=\"\" src=\"https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a3.png\" alt=\"\">\r\n<img title=\"\" src=\"https://github.com/hansalemaos/PrettyColorPrinter/raw/main/a5.png\" alt=\"\">\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Pandas DataFrames / Pandas Series / Print colored Numpy arrays / lists / dicts / tuples!",
    "version": "0.45",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/PrettyColorPrinter"
    },
    "split_keywords": [
        "pandas",
        "numpy",
        "dataframe",
        "series",
        "print",
        "prettyprint",
        "colored",
        "coloured"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "418dc7aefe0b33e4fcc761d9a37485cd57b06283df75302f034ed2ea22014e54",
                "md5": "716a659868ac92614f635e04886e1dfb",
                "sha256": "966183d5268650307a0467c88cde17d0ec79c09d2256e5b70d2fc27a18e6629f"
            },
            "downloads": -1,
            "filename": "PrettyColorPrinter-0.45-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "716a659868ac92614f635e04886e1dfb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 36176,
            "upload_time": "2024-02-23T00:04:12",
            "upload_time_iso_8601": "2024-02-23T00:04:12.508482Z",
            "url": "https://files.pythonhosted.org/packages/41/8d/c7aefe0b33e4fcc761d9a37485cd57b06283df75302f034ed2ea22014e54/PrettyColorPrinter-0.45-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3130bdaedb739af1c980792ecfeaf90337034786af8656320e6ee49884d78af0",
                "md5": "92e446e6b33d57971e097a65f51457c8",
                "sha256": "99fc4c910463a412b92a68b811215756e44de305d6f813548e67f550fea5630c"
            },
            "downloads": -1,
            "filename": "PrettyColorPrinter-0.45.tar.gz",
            "has_sig": false,
            "md5_digest": "92e446e6b33d57971e097a65f51457c8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 36794,
            "upload_time": "2024-02-23T00:04:14",
            "upload_time_iso_8601": "2024-02-23T00:04:14.440871Z",
            "url": "https://files.pythonhosted.org/packages/31/30/bdaedb739af1c980792ecfeaf90337034786af8656320e6ee49884d78af0/PrettyColorPrinter-0.45.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-23 00:04:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "PrettyColorPrinter",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "cprinter",
            "specs": []
        },
        {
            "name": "input_timeout",
            "specs": []
        },
        {
            "name": "keyboard",
            "specs": []
        },
        {
            "name": "kthread",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "pandas",
            "specs": []
        },
        {
            "name": "regex",
            "specs": []
        }
    ],
    "lcname": "prettycolorprinter"
}
        
Elapsed time: 0.24112s