Home > OS >  Saving a dataframe after for loop
Saving a dataframe after for loop

Time:11-28

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?

CodePudding user response:

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)) 
  • Related