'Shopify API: Most efficient way to bulk edit customer tags?

I'm trying to do a makeshift system which updates the tags of customers using the API.

I have a dataframe with 2 fields - email and tag to be applied:

+----------------------+-----------+
| **email**            | **tag**   |
+----------------------+-----------+
| [email protected]    | active    |
+----------------------+-----------+
| [email protected]    | cancelled |
+----------------------+-----------+
| [email protected]    | example   |
+----------------------+-----------+
| [email protected] | some tag  |
+----------------------+-----------+

I use the following code to iterate through customers and update their tags:

for i in df.index:
    customer_string=str(shopify.Customer.search(query=df['email'][i])) #find id based on email    
    if customer_string!='[]':
        customer_id=customer_string[10:23]
        customer=shopify.Customer.find(customer_id)
        customer.tags=str(df['tag'][i])
        customer.save()

Would there be a more efficient way to update these tags, if it's intended to be done on regular basis?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source