Skip to content

Instantly share code, notes, and snippets.

@austinbrian
Last active April 27, 2020 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinbrian/c7970de49bed4010fbeb64e0b3c70b89 to your computer and use it in GitHub Desktop.
Save austinbrian/c7970de49bed4010fbeb64e0b3c70b89 to your computer and use it in GitHub Desktop.
A couple of useful settings for displaying pandas dataframes
# Pandas settings to include on import
import pandas as pd
import numpy as np
pd.set_option('display.max_rows',1000)
pd.set_option('display.max_columns',1000)
# Includes commas in outputs > 1,000, and formats as integers if integers
# If not integers, formats to two decimal places
pd.set_option('display.float_format', lambda x: "{:,.0f}".format(x) if x.is_integer()
else "{:,.2f}".format(x))
# a more complicated version
pd.set_option('display.float_format', lambda x: "{:,.0f}".format(x) if x.is_integer() else (
"{:,.2f}".format(x) if x>1 else (
"{:,.2%}".format(x) if x > -1 else (
"{:,.2f}".format(x))))
)
pd.options.mode.chained_assignment = None # default='warn'
# Set shell to show all lines of output
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment