Home > Blockchain >  Append data to newly added column in Python
Append data to newly added column in Python

Time:04-24

I used this line to add a new empty column to my DataFrame

df.insert(3, 'Summary', '')

Then, I want to fill each raw of this new column with text in this loop at the same position of index i

    with open("drive/MyDrive/First_hotel.txt","a") as f:
      for i in range(number_of_review_per_hotel(Hotel_names[0])) :     
        toSummarize = df['English_reviews'][i]
        text = summarizer(toSummarize, max_length = 10)[0]['summary_text']
        ****
        f.write(text ' ')

What should I write in the place of ***?

CodePudding user response:

Use:

temp = df.index
df.loc[temp[i], 'Summary'] = text
  • Related