Created
August 13, 2020 03:54
-
-
Save MJafarMashhadi/2203eab2120182715f25662fa304b093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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