Applying comma seperator formatting to an entire DataFrame in python 3
<p>I want to format all numbers in a DataFrame to have comma seperators (e.g. 1,000,000 instead of 1000000). It can be applied to a single number using <code>'{:,}'.format(number)</code>. Naively applying the same to a DataFrame gives the error</p>

<pre><code>    TypeError: non-empty format string passed to object.__format__
</code></pre>

<p>Is there a way to efficiently apply the same formatting to a DataFrame? Thanks!</p>

<p>Use <code>applymap</code></p>

<pre><code>df = pd.DataFrame(np.random.randint(1000, 10000, (5, 5)))

df.applymap('{:,}'.format)
</code></pre>

<p><a href="http://i.stack.imgur.com/ikJ1k.png" rel="nofollow"><img src="http://i.stack.imgur.com/ikJ1k.png" alt="enter image description here"></a></p>

python python-3.x pandas dataframe formatting