Saving a dataframe after for loop

Question:

I run for loop on a dataframe. like below

for row in df["findings"]:
   GPT2_model = TransformerSummarizer(transformer_type="GPT2",transformer_model_key="gpt2-medium")
   full = ''.join(GPT2_model(row, min_length=60)) 

In this loop I extract one row at a time and then the GPT2_model model process and returns that row.
Now there are about 4000+ rows, I want to save these preprocessed rows in a datframe but don’t know how?

Asked By: Jacob

||

Answers:

Try not using a for loop, cause the advantage of using pandas is exactly to avoid the for loops
in your place I would try :

GPT2_model = TransformerSummarizer(transformer_type="GPT2",transformer_model_key="gpt2-medium")
df["new_column"] = ''.join((df["findings"].apply(GPT2_model), min_length=60)) 
Answered By: sdkayb
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.