Skip to content

Instantly share code, notes, and snippets.

@data-enhanced
Last active February 12, 2021 14:51
Show Gist options
  • Select an option

  • Save data-enhanced/0c48586f36e8cd27ffad8fe076d62c4e to your computer and use it in GitHub Desktop.

Select an option

Save data-enhanced/0c48586f36e8cd27ffad8fe076d62c4e to your computer and use it in GitHub Desktop.
Format output of pandas describe() method

Pandas Describe() formatted

Format numbers output from the pandas df.describe() method. For instance, instead of outputting scientific notation, we can have numbers with thousands separators and a desired number of decimals.

For reference, see:

When using describe for a data frame, use .apply and a lambda function to apply the formatting to every number.

  • To change the number of decimals, change the number before the f
  • To remove the thousands separator remove the comma

df.describe().apply(lambda s: s.apply('{:,.0f}'.format))

When using describe with a single column or a series, use the .map method instead:

df['Column'].describe().map('{:,.0f}'.format)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment