stu_dent
stu_dent

Reputation: 47

Append data to newly added column in Python

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 ***?

Upvotes: 1

Views: 57

Answers (1)

keramat
keramat

Reputation: 4543

Use:

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

Upvotes: 2

Related Questions