# Format Table Values as Currency (US Dollars $) LaTeX

**URL:** <https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890>\
**Category:** 📊 Plotly Python\
**Created:** [April 10, 2017, 8:19pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890 "2017-04-10T20:19:20Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [April 10, 2017, 8:19pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/1 "2017-04-10T20:19:20Z")

</div>

Hi all,

I’m trying to add currency values (in US dollars $) to Plotly table using Python. If I use this operator to format a dataframe column:  
`campaigns_df['Cost'] = campaigns_df['Cost'].map("${:,.0f}".format)`

[plot.ly](http://plot.ly) table thinks I’m trying to use LaTeX - [https://plot.ly/python/table/](https://plot.ly/python/table/) - and I get a pretty LaTeX number without a dollar sign.

I tried to add a backslash before a dollar sign to get [the result I need](http://tex.stackexchange.com/questions/81670/how-are-amounts-of-money-to-be-typeset):  
`campaigns_df['Cost'] = campaigns_df['Cost'].map("\${:,.0f}".format)`

but this didn’t help. All other scenarios, like concatenating a $ to a column value, didn’t work as well.

Does anyone of you know how to add a dollar sign to plotly table?

Cheers,  
Viola

---

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [April 17, 2017, 5:35pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/2 "2017-04-17T17:35:32Z")

</div>

Any LaTeX/plotly experts here? Seems like a trivial question, but turns out to be painful!

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jack/32/11_2.png) [@jack](https://community.plotly.com/u/jack)\
**Post date:** [April 21, 2017, 5:08am UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/3 "2017-04-21T05:08:22Z")

</div>

Try using the HTML encoding for the dollar sign -`&#36;`

For example:  
`Price: &#36;350k - &#36;450k`

(Credit for this idea: [http://stackoverflow.com/questions/40753033/plotly-js-using-two-dollar-signs-in-a-title-without-latex](http://stackoverflow.com/questions/40753033/plotly-js-using-two-dollar-signs-in-a-title-without-latex))

---

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [April 21, 2017, 4:26pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/4 "2017-04-21T16:26:26Z")

</div>

Thanks so much @jack! It worked perfectly!

---

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [July 7, 2017, 6:37pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/5 "2017-07-07T18:37:03Z")

</div>

Hi @jack, this method suddenly stopped working (I made no changes to my script) and now prints _&#36_ instead of the dollar sign. Here is the syntax:

`campaigns_df['Cost'] = campaigns_df['Cost'].map("&#36;{:,.0f}".format)`

I have updated to the latest plotly version. Has anything changed since April? Thanks!

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jack/32/11_2.png) [@jack](https://community.plotly.com/u/jack)\
**Post date:** [July 7, 2017, 6:52pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/6 "2017-07-07T18:52:27Z")

</div>

Hm, I’m not sure, @etienne might know though - I think plotly.js started disallowing some HTML encoded symbols for security reasons.

---

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [July 7, 2017, 7:06pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/7 "2017-07-07T19:06:41Z")

</div>

Thank you @jack appreciate your quick reply.

@etienne, any idea on why this can be happening?

---

<div class="post-metadata">

**Author:** ![jack](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jack/32/11_2.png) [@jack](https://community.plotly.com/u/jack)\
**Post date:** [July 7, 2017, 7:12pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/8 "2017-07-07T19:12:34Z")

</div>

Worst case, we’re about 1 week from having native plotly.js tables, which will definitely have broader character support. You can see a preview here:  
[https://github.com/plotly/plotly.js/pull/1834](https://github.com/plotly/plotly.js/pull/1834)

The current Python tables are a bit of a hack using plotly.js heatmaps and annotations.

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [July 10, 2017, 4:44pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/9 "2017-07-10T16:44:54Z")

</div>

@Viola With the latest Plotly version 2.0.12 it works with the dollar sign given as in a LaTeX file:

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/4/4b2a692cd8517a3f2a4bc1d305e8045f9613c268.PNG)

---

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [July 10, 2017, 5:57pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/10 "2017-07-10T17:57:35Z")

</div>

@empet, Thank you. It doesn’t work for me though with the latest versions:  
 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/9/94677c27e6a50d02ea9a4433ddc7f5e1522c2415.png)

I wonder what else it depends on.

@jack Great, thank you!

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [July 10, 2017, 7:16pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/11 "2017-07-10T19:16:45Z")

</div>

@Viola I realized that this distinct behaviour manifests because I ran the code in a Jupyter Notebook, that renders LaTeX. Pandas works with ASCII code for dollar in Python 2.7, and unicode in Python 3.

Hence just try this version, that worked for me in Python 2.7:

`df['Cost'] = df['Cost'].map("\x24{:,.0f}".format)`

respectively:

`df['Cost'] = df['Cost'].map(u"\u0024{:,.0f}".format)`

with Python 3.

---

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [July 10, 2017, 8:13pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/12 "2017-07-10T20:13:08Z")

</div>

Thanks a lot @empet. It did print the dollar sign as expected, but once I add it in Plotly’s table it formats in LaTeX:

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/e/ede6265fac781cccc836093893a009c3a5abffcd.png)

So I’m back at square one.

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [July 10, 2017, 8:56pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/13 "2017-07-10T20:56:31Z")

</div>

If you convert the numerical values to string, then Plotly will display the string `\x24’+‘10000’ with a a dollar in front of 10000.

---

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [July 10, 2017, 9:40pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/14 "2017-07-10T21:40:35Z")

</div>

@empet, I tried that originally, but it didn’t help. Am I missing something? It seems trivial, but looks like it is not.

`campaigns_df['Cost'] = '\x24' + campaigns_df['Cost'].map(str)`  
or  
`campaigns_df['Cost'] = '\x24' + campaigns_df['Cost'].astype('str')`

still gives me the below:

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/2/2358e3798252c8255d2a84d9b4077887c3f8aa1e.png)

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [July 10, 2017, 9:54pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/15 "2017-07-10T21:54:05Z")

</div>

I’ve just modified the code for an answer to other user that was interested in subplots of tables and with the last version it worked: [https://plot.ly/~empet/14372](https://plot.ly/~empet/14372). Try to list the content of your column of interest, after conversion to str and insertion of `'\x24'` as prefix. Maybe there is something wrong.

---

<div class="post-metadata">

**Author:** ![Viola](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/viola/32/1095_2.png) [@Viola](https://community.plotly.com/u/Viola)\
**Post date:** [July 10, 2017, 10:41pm UTC](https://community.plotly.com/t/format-table-values-as-currency-us-dollars-latex/3890/16 "2017-07-10T22:41:32Z")

</div>

No it shows correctly in the editor, but not in the table… I’ll update this thread if I figure this one out.
