<?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: Numpy Pivot: Summary Statistics Results in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17773#M1373</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Peter it is called Observation_Summary_1.pdf in Numpy Repository... I won't post the link here to save getting a whole bunch of "the link doesn't work" questions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 06 May 2016 13:09:14 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2016-05-06T13:09:14Z</dc:date>
    <item>
      <title>Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17766#M1366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;!I recently posted the following discussion &lt;A _jive_internal="true" href="https://community.esri.com/thread/174845" target="_blank"&gt;Convert Summary Table Structure (Python)&lt;/A&gt;​ which I thought I'd resolved with the help from &lt;A _jive_internal="true" href="https://community.esri.com/people/Dan_Patterson" target="_blank"&gt;Dan Patterson&lt;/A&gt;​. Please refer to my previous post for the explanation and the reasoning behind the following. Where I'm currently at is that I have been able to pivot the column &lt;STRONG&gt;Time&lt;/STRONG&gt; and populate it with the values from the statistics count results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The last hurdle that I'm trying to achieve is to merge the results so that there isn't a new record for each time interval as shown below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="198544" alt="Incorrect_Pivot_Results.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/198544_Incorrect_Pivot_Results.png" style="width: 620px; height: 60px;" /&gt;&lt;/P&gt;&lt;P&gt;Incorrect Pivot Results:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Correct_Pivot_Results.png" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/198418_Correct_Pivot_Results.png" style="width: 620px; height: 69px;" /&gt;&lt;/P&gt;&lt;P&gt;Correct Pivot Results:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;'''
Created on April 6, 2016

Summarise Number of Buildings

per Time Interval

(5, 10, 15, 25, 30, 60)

@author: PeterW
'''
# import site-packages and modules
from pathlib import Path
import numpy.lib.recfunctions as rfn
import pandas as pd&amp;nbsp; # Pandas version 0.13.0
import arcpy


# set arguments
saa_stats_table = r"E:\Projects\2016\G112224\Models\Schools\Schools_Combined_160505.gdb\Botrivier_Prim_SAA_Stats"

# environment settings
arcpy.env.overwriteOutput = True
fgdb = Path(saa_stats_table).parents[0]


def pivot_table(saa_stats_table, fgdb):
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields = [f.name for f in arcpy.ListFields(saa_stats_table)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; table_recarray = arcpy.da.TableToNumPyArray(saa_stats_table, fields)&amp;nbsp; # @UndefinedVariable
&amp;nbsp;&amp;nbsp;&amp;nbsp; print table_recarray
&amp;nbsp;&amp;nbsp;&amp;nbsp; df = pd.DataFrame(table_recarray[fields])
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot = df.pivot(index="OBJECTID",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; columns="TIME",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values="FREQUENCY").fillna(0, downcast="infer")
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_fields = pivot.columns.values
&amp;nbsp;&amp;nbsp;&amp;nbsp; # rename pivot fields with prefix "TIME"
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot.columns = [("{0}{1}".format("TIME", field)) for field in pivot_fields]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # convert pandas dataframe to record array
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_recarray = pivot.to_records(index=False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_type = pivot_recarray.dtype.descr
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_type_new = [(x[0], x[1].replace(x[1], "&amp;lt;i2")) for x in pivot_type]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # change pivot record array data type to short integer
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_recarray = pivot_recarray.astype(pivot_type_new)
&amp;nbsp;&amp;nbsp;&amp;nbsp; fields2 = ["TOWN", "SETTLEMENTNAME", "NAME"]
&amp;nbsp;&amp;nbsp;&amp;nbsp; table_type_new = [(str(x), "&amp;lt;U25") for x in fields2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # change table array data type to unicode 50 characters
&amp;nbsp;&amp;nbsp;&amp;nbsp; table_recarray = table_recarray[fields2].astype(table_type_new)
&amp;nbsp;&amp;nbsp;&amp;nbsp; recarray_list = [table_recarray, pivot_recarray]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # merge table and pivot record array
&amp;nbsp;&amp;nbsp;&amp;nbsp; summary_array = rfn.merge_arrays(recarray_list, flatten=True, usemask=False)
&amp;nbsp;&amp;nbsp;&amp;nbsp; summary_table = str(Path(fgdb, "SAA_Stats_Test"))
&amp;nbsp;&amp;nbsp;&amp;nbsp; # convert merged record array to file geodatabase table
&amp;nbsp;&amp;nbsp;&amp;nbsp; if arcpy.Exists(summary_table):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(summary_table)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.da.NumPyArrayToTable(summary_array, summary_table)&amp;nbsp; # @UndefinedVariable
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.da.NumPyArrayToTable(summary_array, summary_table)&amp;nbsp; # @UndefinedVariable

pivot_table(saa_stats_table, fgdb)
#&lt;/PRE&gt;&lt;P&gt;Python Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any advice in how I can achieve the following. I suspect it would need to be done either before or after I have merged the two arrays (line 50). Any other alternative that won't require me having to change all my code would really be appreciated as time is a factor at the moment. I urgently need to get my results out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NB. Please note I dont have an Advance Licence so Pivot_Table is not an option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:42:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17766#M1366</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2021-12-10T20:42:57Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17767#M1367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Peter, in Column C in the both images... they are different and the latter image has 2 unique rows, which is correct.&amp;nbsp; In order to consolidate and add the rows together column C must contain the same unique values so you are going to have to truncate Botrivier Prim to Botrivier, or append Prim to the second row.&amp;nbsp; The classification needs to be unique, not unique-ish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 10:56:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17767#M1367</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-05-06T10:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17768#M1368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Column C would be the same. The reason that the second image is different was just to show that there could be values from Time5 - Time60 depending of the statistics results. The second record within the second image would have been four records within the first image. I've replaced the second image to show only one record and filled the empty columns to depict that the Time range of possible results depending on the statistics results.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 11:15:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17768#M1368</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2016-05-06T11:15:16Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17769#M1369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are now getting figure 1 could you run &lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/dissolve.htm" title="http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/dissolve.htm"&gt;Dissolve—Help | ArcGIS for Desktop&lt;/A&gt;&amp;nbsp; and sum fields D-J&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 12:18:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17769#M1369</guid>
      <dc:creator>WesMiller</dc:creator>
      <dc:date>2016-05-06T12:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17770#M1370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Wes&lt;/P&gt;&lt;P&gt;The following is an output from Summary Statistics so you can't use Dissolve, thanks for the suggestion though. &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/sad.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 12:34:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17770#M1370</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2016-05-06T12:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17771#M1371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've found a temporary solution to the following, using Summary Statistics. I'd really appreciate any advice in how to alter my NumPy Function to get the results out within the correct format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="198687" alt="Summary_Statistics_Results.png" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/198687_Summary_Statistics_Results.png" style="width: 620px; height: 364px;" /&gt;&lt;/P&gt;&lt;P&gt;The following will allow me to get my results out today.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="198688" alt="Summary_Statistics_Table.png" class="image-2 jive-image" height="131" src="https://community.esri.com/legacyfs/online/198688_Summary_Statistics_Table.png" style="height: 130px; width: 1046.75px;" width="1047" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the advice so far.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 12:48:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17771#M1371</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2016-05-06T12:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17772#M1372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Peter, check my documentation closely, I successfully got it to summarize within a time period, I don't know why yours is different, I haven't looked at the Pandas shroud over the base numpy implementation.&amp;nbsp; I will look through when I get a chance but there is definitely no need to summarize but for now that will have to be the work around.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking at your last example, the implementation I am referring to does a np.unique and np.where on whatever field, then sums for the remaining numeric columns (or specified numeric columns)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 12:59:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17772#M1372</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-05-06T12:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17773#M1373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Peter it is called Observation_Summary_1.pdf in Numpy Repository... I won't post the link here to save getting a whole bunch of "the link doesn't work" questions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 13:09:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17773#M1373</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-05-06T13:09:14Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17774#M1374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan&lt;/P&gt;&lt;P&gt;Thanks Dan, will have a look at the following.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 May 2016 15:18:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17774#M1374</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2016-05-06T15:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17775#M1375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan&lt;/P&gt;&lt;P&gt;I've used the code example within your &lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;"&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;STRONG&gt;Observation_Summary_1.pdf&lt;/STRONG&gt;" and understand the most of your code, but if you wouldn't mind unpacking from&amp;nbsp; Line 45 to 50. I'm unsure if line 45 is a list comprehension of some sort and not understanding the how its working. &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# coding: utf-8
"""
Dan Patterson:

Numpy Pivot Table Summary

16/05/2016

"""
# import site-packages and modules
import numpy as np
import arcpy

# set input summary table
input_table = r"E:\Projects\2016\G112224\Models\Schools\Schools_Combined_160505.gdb\De_Villiers_Graaff_Hs_SAA_Stats"
output_gdb = r"E:\Python\Testing\dan_patterson_numpy\SAA_Summary_Report_Testing.gdb"


# numpy pivot table function
def pivot_summary(input_table, output_gdb):
&amp;nbsp;&amp;nbsp;&amp;nbsp; # convert summary table to structured numpy array
&amp;nbsp;&amp;nbsp;&amp;nbsp; numpy_fields = ("OBJECTID", "TOWN", "SETTLEMENTNAME",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "NAME", "TIME", "FREQUENCY")
&amp;nbsp;&amp;nbsp;&amp;nbsp; sum_array = arcpy.da.TableToNumPyArray(input_table, numpy_fields)&amp;nbsp; # @UndefinedVariable
&amp;nbsp;&amp;nbsp;&amp;nbsp; # obtain unique records based on first three columns
&amp;nbsp;&amp;nbsp;&amp;nbsp; unique_records = np.unique(sum_array[['TOWN', 'SETTLEMENTNAME', 'NAME']])
&amp;nbsp;&amp;nbsp;&amp;nbsp; # number of unique rows
&amp;nbsp;&amp;nbsp;&amp;nbsp; shp = len(unique_records)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # construct the output array
&amp;nbsp;&amp;nbsp;&amp;nbsp; dt = [('TOWN', 'U20'), ('SETTLEMENTNAME', 'U20'), ('NAME', 'U20'),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ('TIME5', np.int32), ('TIME10', np.int32), ('TIME15', np.int32),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ('TIME20', np.int32), ('TIME25', np.int32), ('TIME30', np.int32),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ('TIME60', np.int32)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; # populate array with zeros
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_array = np.zeros(shp, dtype=dt)
&amp;nbsp;&amp;nbsp;&amp;nbsp; # assign the first three columns
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_array['TOWN'] = unique_records['TOWN']
&amp;nbsp;&amp;nbsp;&amp;nbsp; # the values from the unique test
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_array['SETTLEMENTNAME'] = unique_records['SETTLEMENTNAME']
&amp;nbsp;&amp;nbsp;&amp;nbsp; # everything is sorted
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_array['NAME'] = unique_records['NAME']
&amp;nbsp;&amp;nbsp;&amp;nbsp; # loop through unique records array
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in range(shp):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # pull out the rows that match
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; row_match = sum_array[sum_array[['TOWN', 'SETTLEMENTNAME',
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'NAME']] == unique_records&lt;I&gt;]&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for j in range(len(row_match)):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; column = 'TIME' + str(row_match&lt;J&gt;['TIME'])&lt;/J&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; buildings = row_match&lt;J&gt;['FREQUENCY']&lt;/J&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_array&lt;I&gt;[column] = buildings&lt;/I&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; pivot_table = "{0}\\{1}".format(output_gdb, "Pivot_Table_Summary")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.da.NumPyArrayToTable(pivot_array, pivot_table)&amp;nbsp; # @UndefinedVariable
&amp;nbsp;&amp;nbsp;&amp;nbsp; return pivot_table

pivot_table = pivot_summary(input_table, output_gdb)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="NumPy_Pivot_Table_Results.png" class="image-1 jive-image" height="154" src="https://community.esri.com/legacyfs/online/201086_NumPy_Pivot_Table_Results.png" style="height: 154px; width: 1037.83px;" width="1038" /&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help Dan &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:43:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17775#M1375</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2021-12-10T20:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17776#M1376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Peter, I will check when I get home, but on first look, that area is a lot of array slicing with conditions (on a wild guess).... this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;row_match = sum_array[sum_array[['TOWN', 'SETTLEMENTNAME',&amp;nbsp; 'NAME']] == unique_records&lt;I&gt;]&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;means the row_match is the slice of the array sum_array, where the columns (town, sett.. name) in the array, are equal to those in the unique_records condition.&amp;nbsp; So in short it isn't a list comprehension but I wrote the slice in verbose form, matching the query to the unique conditions, doing them one condition at a time rather than all at once.&amp;nbsp; This is supposed to make it more readable (kindof didn't work as planned)&amp;nbsp; but I will try to lay out a flowchart then&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 May 2016 13:16:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17776#M1376</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-05-17T13:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: Numpy Pivot: Summary Statistics Results</title>
      <link>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17777#M1377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Dan, much appreciated &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 May 2016 13:42:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/numpy-pivot-summary-statistics-results/m-p/17777#M1377</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2016-05-17T13:42:55Z</dc:date>
    </item>
  </channel>
</rss>

