Pandas: Setting the number of maximum rows
To control the number of rows displayed in a DataFrame, utilize the command pd.set_option('display.max_rows', num), where num is a specified max number of rows or use None for unlimited rows.
Quick modifications: Adjusting display settings
Pandas provides a convenient way to temporarily adjust display options within a specified context using pd.option_context. The changes apply only to the specific block of code.
Beautifying your DataFrame: width and precision
Set the specific display width and decimal precision for your DataFrame. Customize to fit your preference with 'display.width' and 'display.precision'.
Tailoring your environment: contextual adaptations
Environment-specific display options
Different environments will have varied display behaviors. For example, Jupyter notebooks may render DataFrames using df.head(500) instead of set_option.
Back to defaults
It's crucial to remember how to revert to default settings when needed. Use pd.reset_option to revert a single option and pd.reset_option('all') for all.
Discover options with tab-completion
In iPython environments like Jupyter, you can explore options by typing pd.options. and pressing Tab to see all the settings within your reach.
Going beyond: Exploring additional options
Explore more display options
To look into all available options, use pd.describe_option('display') to discover and tweak your data display.
Jupyter Notebook specifications
Jupyter allows more extensive DataFrame display adjustments like:
- Converting the DataFrame to HTML with a static display using:
HTML(df.to_html(max_rows=10)). - Adding custom CSS styles to such output with
df.style.set_table_styles.
Was this article helpful?