-2

I have the following dataframe in python: enter image description here

I would like to convert from word ok(index = 0) to something(index =24) into one sentence based on end_sentence column value which is 1 to indicate end of a sentence. Similar from Night(index=25) to significant (index=41) into another sentence

1 Answers1

0
sentences = []
indices = df.index[df['end_sentence'] == 1]

begin = 0
for i in indices:
    end = i + 1
    sentence = ' '.join(list(df['word'][begin:end]))
    sentences.append(sentence)
    begin = end
Pramote Kuacharoen
  • 1,496
  • 1
  • 5
  • 6