How to show thousands separator for pandas value counts?

MilkyWay001

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?

MWE:

df = pd.DataFrame({'A': [1,1,1,2,2]*10000})

df['A'].value_counts()

1    30000
2    20000
Name: A, dtype: int64

Attempts

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
Kenan

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to insert a comma as a thousands separator in a pandas dataframe column?

How to set the thousands place separator in pandas read_csv?

How to force dot on thousands separator?

How to set thousands separator in Java?

How to the ISU thousands separator (space) ?

How to set thousands separator in R?

pandas value_counts (show values and ratio)

DecimalFormatter with thousands separator 0 value returning .00

How do I parse numbers with thousands separator in pandas read_csv?

How to change thousands separator to apostrophe in format string

how to change thousands separator for blank in R plotly?

How to determine Thousands Separator using Format in VBA

Pandas: how to do value counts within groups

How to subset a pandas dataframe on value_counts?

how to sort the result by pandas.value_counts

How to groupby().transform() to value_counts() in pandas?

how to nested value_counts in pandas

Pandas: How to merge value counts in a grouped dataframe

R Plotly hooverinfo - adjust the number format to show thousands separator

Insert a comma as thousands separator between several pandas df columns

Remove thousands separator from a line starting with Total Value

How to show counts of null string-like column values in pandas

value counts of group by in pandas

value counts by group in pandas

how to get return value of value_counts() in pandas with right order

Thousands separator in printf in zsh

Thousands separator formatting with Databinding

Parsing decimal with thousands separator

Quoting with thousands separator