Ben Chuanlong Du's Blog

It is never too late to learn.

Options for the pandas Package in Python

In [5]:
import numpy as np
import pandas as pd

Max Number of Columns to Display

In [3]:
pd.options.display.max_columns = 100

Max Number of Rows to Display

In [4]:
pd.options.display.max_rows = 500

Max Column Width to Display

You can control the max column width of pandas display using the option pd.options.display.max_colwidth .

Set pd.options.display.max_colwidth to a specific limit.

In [3]:
pd.options.display.max_colwidth = 100

Set pd.options.display.max_colwidth to None which imposes no limit.

In [3]:
pd.options.display.max_colwidth = None
In [4]:
df = pd.DataFrame(
    {
        "id": [1, 2, 3, 4, 5],
        "link": [
            "http://a_super_loooooooooooooooooooooooooooooooong_link.com",
            "",
            "",
            "",
            "",
        ],
    }
)
df
Out[4]:
id link
0 1 http://a_super_loooooooooooooooooooooooooooooooong_link.com
1 2
2 3
3 4
4 5
In [2]:
df
Out[2]:
id link
0 1 http://a_super_loooooooooooooooooooooooooooooooong_link.com
1 2
2 3
3 4
4 5

Display Formatting of Floating Numbers

In [10]:
df = pd.DataFrame(np.random.randint(100, 10000, size=(4, 2)), columns=["a", "b"])
df.head()
Out[10]:
a b
0 9130 4028
1 7134 4415
2 3279 8791
3 2602 8575
In [11]:
df.dtypes
Out[11]:
a    int64
b    int64
dtype: object
In [12]:
pd.options.display.float_format = "{:,}".format
In [13]:
df
Out[13]:
a b
0 9130 4028
1 7134 4415
2 3279 8791
3 2602 8575
In [8]:
dir(pd.options.display)
Out[8]:
['chop_threshold',
 'colheader_justify',
 'column_space',
 'date_dayfirst',
 'date_yearfirst',
 'encoding',
 'expand_frame_repr',
 'float_format',
 'height',
 'html',
 'large_repr',
 'latex',
 'line_width',
 'max_categories',
 'max_columns',
 'max_colwidth',
 'max_info_columns',
 'max_info_rows',
 'max_rows',
 'max_seq_items',
 'memory_usage',
 'multi_sparse',
 'notebook_repr_html',
 'pprint_nest_depth',
 'precision',
 'show_dimensions',
 'unicode',
 'width']

Styling

  1. Avoid applying styling on large pandas DataFrames, as pandas styling (using DataFrame.style.format) is extremely slow on large data frames. It is suggested that you always use DataFrame.head, DataFrame.tail or filtering to limit the size of a DataFrame before applying styling to it. Another good way is to display a pandas DataFrame using a widget extension. For more details, please refer to JupyterLab Extensions for Spreadsheet.
In [ ]:
 
In [ ]:
 

Comments