Skip to content

Instantly share code, notes, and snippets.

@MJafarMashhadi
Created August 13, 2020 03:54
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 MJafarMashhadi/2203eab2120182715f25662fa304b093 to your computer and use it in GitHub Desktop.
Save MJafarMashhadi/2203eab2120182715f25662fa304b093 to your computer and use it in GitHub Desktop.
class PandasFloatFormatter:
def __init__(self, new_format: str):
self.new_format = new_format.format
self.old_format = None
def __enter__(self):
self.old_format = pandas.options.display.float_format
pandas.options.display.float_format = self.new_format
def __exit__(self, exc_type, exc_val, exc_tb):
pandas.options.display.float_format = self.old_format
# Example
with PandasFloatFormatter('{:,.2f}%'):
print(paper_results.to_latex())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment