Instantly share code, notes, and snippets.
data-enhanced/pandas_describe_formatted.md
Last active November 21, 2025 08:14- Star 1 (1) You must be signed in to star a gist
- Fork 0 (0) You must be signed in to fork a gist
-
Select an option
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/data-enhanced/0c48586f36e8cd27ffad8fe076d62c4e.js"></script> - Save data-enhanced/0c48586f36e8cd27ffad8fe076d62c4e to your computer and use it in GitHub Desktop.
Select an option
No results found
Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/data-enhanced/0c48586f36e8cd27ffad8fe076d62c4e.js"></script> Save data-enhanced/0c48586f36e8cd27ffad8fe076d62c4e to your computer and use it in GitHub Desktop. Download ZIP Format output of pandas describe() method Raw pandas_describe_formatted.mdPandas .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.
When using .describe with an entire dataframe, 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)
For reference, see:
- https://stackoverflow.com/a/47207283
- https://mkaz.blog/code/python-string-format-cookbook/
- https://docs.python.org/3/library/string.html#formatstrings