Thanks for the reply.

My main function (i.e. looping through 1 million samples for text manipulation) is actually done on a dataframe directly and it uses the below format:

df[ColA] = df[ColB].apply(my_function).

It's the "my_function" bit that has for loops that cannot be avoided.

For example let's take a very simple inbuilt function str.lower() for "HELLO WORLD". The source code for this function has for loops and there is no alternative to for loops (in my opinion)

The problem in my case as well is that loops can't be avoided as my string manipulation is not as simple as concatenation always. Many a times there are regex checks involved across a list 400 words (this list is not in the dataframe). Other times it's a huge function which requires looping through a tokenized spacy doc object (to find entities like Company names)