我正在尝试使用'{:,}’.格式(数字),如下例所示,格式化pandas数据帧中的数字:
# This works for floats and integers
print '{:,}'.format(20000)
# 20,000
print '{:,}'.format(20000.0)
# 20,000.0
问题是,对于具有整数的数据帧不起作用,并且在具有float的数据框中工作正常.看看例子:
# 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
#
#
0#
20000#
# Works OK
df_float = DataFrame({"A": [20000.0, 10000.0]})
print df_float.to_html(float_format=lambda x: '{:,}'.format(x))
# Example of result
#
#
0#
20,000.0#
我做错了什么?