It is really a pain that certain highly used functions are only available an advanced license level. This is an alternate to the options of using Excel to produce a pivot table from ArcMap tabular data.
Flipping rows and columns in data generally works smoothly when the table contains one data type, whether it be integer, float or text. Problems arise when you add stuff to Excel is that it allows you do so without regard to the underlying data. So, columns get mixed data types and rows do as well. Uniformity by column is the rule.
In NumPy, each column has a particular data type. The data type controls the operations that can be performed on it. Numeric fields can have all the number type operations used...similarly for string/text fields. It is possible to cast a field as an "object" type allowing for mixed type entries. The nice thing about this type, is that you can't really do anything with it unless it is recast into a more useful form...but it does serve as a conduit to other programs or just for presentation purposes.
In the following example, the line
a = # your array goes here
can be derived using
a = arcpy.FeatureClasstoNumPyArray(....) FeatureClassToNumPyArray
The nature of np.unique change in version 1.9 to get the number of unique classes as well. So if you are using ArcGIS Pro, then you can use the newer version if desired by simply changing line 04 below.
a_u, idx, counts = np.unique(a_s, return_inverse=True, unique_counts=True)
Array conversion to summary table or pivot table | Input and output |
---|---|
Well... who needs an advanced license or excel ... Assume we have an array of the format shown in the Input section. We can determine the counts or sums of unique values in a field, using the following.
The trick is to set the data type to 'object'. You just use FeatureClassToNumPyArray or TableToNumPyArray and their inverses to get to/from array format. Ergo....pivot table should NOT be just for an advanced license For all-ish combos, you can just add the desired lines to the above
| Input table with the following fields 'ID', 'X', 'Y', 'Class', 'Count'
|
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.