我正在使用pandas数据框的值计数方法,发现它输出的整数没有千位分隔符。我们如何用千位分隔符获得输出?
df = pd.DataFrame({'A': [1,1,1,2,2]*10000})
df['A'].value_counts()
1 30000
2 20000
Name: A, dtype: int64
np.set_printoptions(formatter={'int_kind': '{:,}'.format})
pd.options.display.float_format = '{:,}'.format
df = pd.DataFrame({'A': [1,1,1,2,2]*10000})
df['A'].value_counts()
# still could not get thousands separator
1 30000
2 20000
Name: A, dtype: int64
当您设置pd.options.display.float_format = '{:,}'.format
时它将适用于浮点数而不是整数
df['A'].value_counts().astype(float)
1 30,000.0
2 20,000.0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句