Index "Column A" for unique values, then recursively group "Column B" values based on those uniques I have two levels of product variants in a table field. If the product uses Secondary Variants, I need a way to search the Primary Variants column for unique values, then output individually grouped Secondary variants.

Both Primary and Secondary Variants are unique for each product.

Is there a way to do this with TWIG/Craft templates? If not, what do you recommend? Query JSON? Plug-in?
Possible, yes. But if you should do it with Twig alone is a totally different thing. There's other ways to do that in Craft,
e.g. with relations (Entries Fields) and splitting your Products and their variants into separate sections. Or what about using a structure,
with your variants being child entries to the product?

But here's how you do that with your table field (totally legitimate in my opinion, one advantage being the ease of use for the Client):

{# Prepare variable before loop #}
{% set myVariants = [] %}

{% for row in myTableField %}

    {# Concatenate a string to the value to prevent it from being numeric #}
    {% set variantKey = 'key' ~ row.col1 %}

    {% if variantKey not in myVariants|keys %}

        {# Insert a new key and add the first value to it #}
        {% set myVariants = myVariants|merge({ (variantKey): [row.col2] }) %}

    {% else %}

        {# The key already exists, so merge the value to the existing ones #}
        {% set myVariants = myVariants|merge({ (variantKey): myVariants[variantKey]|merge([row.col2]) }) %}

    {% endif %}

{% endfor %}


This is how you print it:

&lt;ul class="variantsLevel1"&gt;
    {% for variantKey, variantsLevel1 in myVariants %}
        &lt;li&gt;

            {# Remove the string from our key again #}
            {{ variantKey|slice(3) }}

            &lt;ul class="variantsLevel2"&gt;
                {% for variantLevel2 in variantsLevel1 %}
                    &lt;li&gt;{{ variantLevel2 }}&lt;/li&gt;
                {% endfor %}
            &lt;/ul&gt;

        &lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;