<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Pandas Styler format justify prefix left value right (e.g. $ accounting format) in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pandas-styler-format-justify-prefix-left-value/m-p/1351262#M69259</link>
    <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am using the Pandas Styler style.format() method to deal with a currency column.&amp;nbsp; Sample code and format is :&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd

df = pd.DataFrame({'quantity':[2, 45, 322],
                   'unit_cost': [1005.00, 1.92, 0.50]})
df['cost'] = df['quantity'].multiply(df['unit_cost'])

formats = (
        {
           'quantity': "{:,.0f}".format,
           'unit_cost': "$ {:,.2f}".format,
           'cost': "$ {:,.2f}".format,
        }
    )

dfs = df.style.format(formats)&lt;/LI-CODE&gt;&lt;P&gt;And the resulting styled dataframe is:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_0-1700407875545.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/86506i8238C2974D476229/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_0-1700407875545.png" alt="TylerT_0-1700407875545.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However, I'm looking for more of an accounting look where the $ (dollar sign) is justified and aligned left such as this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_1-1700408006864.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/86507iD2D7BD7E9BC4DDEF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_1-1700408006864.png" alt="TylerT_1-1700408006864.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any suggestions on how to write the format to achieve this would be appreciated.&amp;nbsp; Thank you.&lt;BR /&gt;&lt;BR /&gt;Tyler&lt;/P&gt;</description>
    <pubDate>Sun, 19 Nov 2023 15:35:46 GMT</pubDate>
    <dc:creator>TylerT</dc:creator>
    <dc:date>2023-11-19T15:35:46Z</dc:date>
    <item>
      <title>Pandas Styler format justify prefix left value right (e.g. $ accounting format)</title>
      <link>https://community.esri.com/t5/python-questions/pandas-styler-format-justify-prefix-left-value/m-p/1351262#M69259</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;&lt;BR /&gt;I am using the Pandas Styler style.format() method to deal with a currency column.&amp;nbsp; Sample code and format is :&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd

df = pd.DataFrame({'quantity':[2, 45, 322],
                   'unit_cost': [1005.00, 1.92, 0.50]})
df['cost'] = df['quantity'].multiply(df['unit_cost'])

formats = (
        {
           'quantity': "{:,.0f}".format,
           'unit_cost': "$ {:,.2f}".format,
           'cost': "$ {:,.2f}".format,
        }
    )

dfs = df.style.format(formats)&lt;/LI-CODE&gt;&lt;P&gt;And the resulting styled dataframe is:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_0-1700407875545.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/86506i8238C2974D476229/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_0-1700407875545.png" alt="TylerT_0-1700407875545.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;However, I'm looking for more of an accounting look where the $ (dollar sign) is justified and aligned left such as this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TylerT_1-1700408006864.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/86507iD2D7BD7E9BC4DDEF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TylerT_1-1700408006864.png" alt="TylerT_1-1700408006864.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Any suggestions on how to write the format to achieve this would be appreciated.&amp;nbsp; Thank you.&lt;BR /&gt;&lt;BR /&gt;Tyler&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 15:35:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pandas-styler-format-justify-prefix-left-value/m-p/1351262#M69259</guid>
      <dc:creator>TylerT</dc:creator>
      <dc:date>2023-11-19T15:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: Pandas Styler format justify prefix left value right (e.g. $ accounting format)</title>
      <link>https://community.esri.com/t5/python-questions/pandas-styler-format-justify-prefix-left-value/m-p/1351272#M69260</link>
      <description>&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/51325640/accounting-formatting-in-pandas-df" target="_blank"&gt;python - Accounting formatting in Pandas df - Stack Overflow&lt;/A&gt;&amp;nbsp;should do it&lt;/P&gt;</description>
      <pubDate>Sun, 19 Nov 2023 17:47:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pandas-styler-format-justify-prefix-left-value/m-p/1351272#M69260</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-11-19T17:47:22Z</dc:date>
    </item>
  </channel>
</rss>

