How do I display floats as currency with negative sign before currency
<p>consider the <code>pd.Series</code> <code>s</code></p>

<pre><code>s = pd.Series([-1.23, 4.56])
s

0   -1.23
1    4.56
dtype: float64
</code></pre>

<p>I can format floats with pandas <code>display.float_format</code> option</p>

<pre><code>with pd.option_context('display.float_format', '${:,.2f}'.format):
    print s

0   $-1.23
1    $4.56
dtype: float64
</code></pre>

<p>But how do I format it in such a way that I get the <code>-</code> sign in front of the <code>$</code></p>

<pre><code>0   -$1.23
1    $4.56
dtype: float64
</code></pre>

<p>You can substitute the formatting function with your own. Below is just a demo of how it works, you can tune it to your own needs:</p>

<pre><code>def formatfunc(*args, **kwargs):
    value = args[0]
    if value &gt;= 0:
        return '${:,.2f}'.format(value)
    else:
        return '-${:,.2f}'.format(abs(value))

with pd.option_context('display.float_format', formatfunc):
    print(s)
</code></pre>

<p>And you get:</p>

<pre><code>0   -$1.23
1    $4.56
dtype: float64
</code></pre>

python pandas