I am trying to use '{:,}'.format(number) , as in the example below, to format a number in a pandas frame:
# This works for floats and integers print '{:,}'.format(20000)
The problem is that it does not work with a data framework that has integers, and it works fine in a data frame with a float. See Examples:
# Does not work. The format stays the same, does not show thousands separator df_int = DataFrame({"A": [20000, 10000]}) print df_int.to_html(float_format=lambda x: '{:,}'.format(x)) # Example of result # <tr> # <th>0</th> # <td> 20000</td> # </tr # Works OK df_float = DataFrame({"A": [20000.0, 10000.0]}) print df_float.to_html(float_format=lambda x: '{:,}'.format(x)) # Example of result # <tr> # <th>0</th> # <td>20,000.0</td> # </tr>
What am I doing wrong?
source share