Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Options for the pandas Package in Python

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import numpy as np
import pandas as pd

Max Number of Columns to Display

pd.options.display.max_columns = 100

Max Number of Rows to Display

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.

pd.options.display.max_colwidth = 100

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

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

Display Formatting of Floating Numbers

df = pd.DataFrame(np.random.randint(100, 10000, size=(4, 2)), columns=["a", "b"])
df.head()
Loading...
df.dtypes
a int64 b int64 dtype: object
pd.options.display.float_format = "{:,}".format
df
Loading...
dir(pd.options.display)
['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.