I\'m trying to use \'{:,}\'.format(number)
like the example below to format a number in a pandas dataframe:
# This works for floats and integers
pri
You can always cast your table to float64 and then use float_format as you like, especially if you are constructing a small table for viewing purposes. Instead of dealing with ints and floats separately this gives a quick solution.
df.astype('float64',errors='ignore').to_html(float_format=lambda x: format(x,',.2f'))
errors='ignore'
is there to prevent raising an exception when a column can not be converted to floats, like strings.