I was using value counts method of pandas dataframe and found that it outputs the integer without thousands separator. How can we get the output with thousands separator?
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
when you set pd.options.display.float_format = '{:,}'.format
it will work for floats not ints
df['A'].value_counts().astype(float)
1 30,000.0
2 20,000.0
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments