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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.