Py Pandas .format(dataframe) Py Pandas .format(dataframe) pandas pandas

Py Pandas .format(dataframe)


import pandas as pdimport numpy as npdata = np.random.random((8,3))*10000df = pd.DataFrame (data)pd.options.display.float_format = '{:20,.2f}'.formatprint(df)

yields (random output similar to)

                     0                    1                    20             4,839.01             6,170.02               301.631             4,411.23             8,374.36             7,336.412             4,193.40             2,741.63             7,834.423             3,888.27             3,441.57             9,288.644               220.13             6,646.20             3,274.395             3,885.71             9,942.91             2,265.956             3,448.75             3,900.28             6,053.93

The docstring for pd.set_option or pd.describe_option explains:

display.float_format: [default: None] [currently: None] : callable        The callable should accept a floating point number and return        a string with the desired format of the number. This is used        in some places like SeriesFormatter.        See core.format.EngFormatter for an example.