Suppose I have a Pandas DataFrame like:
m1 m2 0 24899 24899 1 15 1
Is there an easy one-liner that allows automatic formatting with a comma thousands separator? Looking for:
m1 m2 0 24,899 24,899 1 15 1
I've seen multi-line solutions or solutions that use lambda functions applied to Series objects that have to be manually specified. Ideally, I'm looking for a dynamic, general solution that would work for a DataFrame with mixed dtypes. Worst case, a solution for the toy example above without having to specify each variable name in my DataFrame.
dtypes
How about this
df['m1'] = df['m1'].map('{:,}'.format)
df['m2'] = df['m2'].map('{:,}'.format)
1.4m articles
1.4m replys
5 comments
57.0k users