<?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 Re: Pandas Pivot Table with rounding in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761495#M58733</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Zachary&lt;/P&gt;&lt;P&gt;I have a few toolset post on the Code sharing site, I don't use pandas, preferring numpy instead, but feel free to examine coding.&lt;/P&gt;&lt;P&gt;Table Tools, has a crosstab/pivot table equivalent, amongst other things&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2018/02/12/table-tools-a-set-of-tools-for-working-with-tabular-data"&gt;/blogs/dan_patterson/2018/02/12/table-tools-a-set-of-tools-for-working-with-tabular-data&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 12 Nov 2018 14:46:41 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2018-11-12T14:46:41Z</dc:date>
    <item>
      <title>Pandas Pivot Table with rounding</title>
      <link>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761492#M58730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm attempting to add in subtotals to a pivot table from a very basic array. The first example I provide I derived on my own, but this has no subtotals for each group.&lt;/P&gt;&lt;P&gt;The second example I borrowed and honestly I don't really get how it works just yet, and I cannot get a round to work.&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;pd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pivot_table&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;round&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;values &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; index &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SUPER_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STRATA'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'OS_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; aggfunc&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;sum&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; margins &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Returns:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="429202" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/429202_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;2nd example:&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;groupby&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SUPER_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;apply&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;lambda&lt;/SPAN&gt; sub_df&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; sub_df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pivot_table&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;index&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STRATA'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'OS_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; values&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; margins&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;IMG __jive_id="429239" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/429239_pastedImage_2.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm guessing there are a number of ways to go about this. Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2018 16:21:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761492#M58730</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2018-11-09T16:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Pandas Pivot Table with rounding</title>
      <link>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761493#M58731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A class="link-titled" href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.round.html" title="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.round.html"&gt;pandas.DataFrame.round — pandas 0.23.4 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.round.html#pandas.Series.round" title="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.round.html#pandas.Series.round"&gt;pandas.Series.round — pandas 0.23.4 documentation&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then there are examples on Stack Exchange&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://stackoverflow.com/questions/19100540/rounding-entries-in-a-pandas-dafaframe" title="https://stackoverflow.com/questions/19100540/rounding-entries-in-a-pandas-dafaframe"&gt;python - Rounding entries in a Pandas DafaFrame - Stack Overflow&lt;/A&gt;&amp;nbsp; This one has a pivot table as an example&lt;/P&gt;&lt;P&gt;Numpy to the rescue!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Nov 2018 23:57:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761493#M58731</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-11-09T23:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Pandas Pivot Table with rounding</title>
      <link>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761494#M58732</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/3116" target="_blank"&gt;Dan Patterson&lt;/A&gt;, thanks for that...I didn't know it would be so simple. Here is what I came up with for my test code before I roll it up into a function. I've always got open ears for improvement! Edit: my pivot table fails to include a grand total. Any suggestions?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;table &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"\\\\fileServer\\MAP_PROJECTS\\LV_WEB\\SDE_CONNECTIONS\\LV_NEXUS.sde\\LV_NEXUS.DATAOWNER.NORTHEAST\\LV_NEXUS.DATAOWNER.NE_HARVEST_OPS"&lt;/SPAN&gt;
HUID &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"669-NMTC-139"&lt;/SPAN&gt;
whereClause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;""" "LV_HARVEST_UNIT_ID" = '{0}' """&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;HUID&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
tableArray &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;da&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;TableToNumPyArray&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;table&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STAND_NUMB'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SUPER_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STRATA'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'OS_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SILV_PRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; where_clause &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; whereClause&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
df &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; pd&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;DataFrame&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;tableArray&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
report &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;groupby&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'SUPER_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;apply&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="keyword token"&gt;lambda&lt;/SPAN&gt; sub_df&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; sub_df&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pivot_table&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;index&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'STRATA'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'OS_TYPE'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'STAND_NUMB'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'SILV_PRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; values&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'ACRES'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; margins&lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token boolean"&gt;True&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
np&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;round&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;report&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 08:21:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761494#M58732</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2021-12-12T08:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Pandas Pivot Table with rounding</title>
      <link>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761495#M58733</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Zachary&lt;/P&gt;&lt;P&gt;I have a few toolset post on the Code sharing site, I don't use pandas, preferring numpy instead, but feel free to examine coding.&lt;/P&gt;&lt;P&gt;Table Tools, has a crosstab/pivot table equivalent, amongst other things&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/blogs/dan_patterson/2018/02/12/table-tools-a-set-of-tools-for-working-with-tabular-data"&gt;/blogs/dan_patterson/2018/02/12/table-tools-a-set-of-tools-for-working-with-tabular-data&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Nov 2018 14:46:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761495#M58733</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-11-12T14:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Pandas Pivot Table with rounding</title>
      <link>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761496#M58734</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan Patterson&lt;/A&gt;‌ thanks! there's some real gold in there. I've bookmarked these and downloaded your table tools. &lt;/P&gt;&lt;P&gt;I ended up getting some help on SE and found an easy way to move the totals. Thanks again Dan!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 13 Nov 2018 13:17:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pandas-pivot-table-with-rounding/m-p/761496#M58734</guid>
      <dc:creator>ZacharyHart</dc:creator>
      <dc:date>2018-11-13T13:17:50Z</dc:date>
    </item>
  </channel>
</rss>

