I have a dataframe in which SOME sentences contain the word 'o'clock' and I want to replace the time mentioned before it with the list of hours I have and put the new sentences in another column, like in the following:
data= {"sentences":["I have a class at ten o'clock", "she is my friend", "she goes to school at eight o'clock"]}
my_list=['two', 'three','five','ten']
what I would like to see is an extra column, with the new sentences like in the following, in which the time is changed to all the times in the list:
Output :
sentences new_sentences
0 I have a class at ten o'clock I have a class at two o'clock, I have a class at three o'clock,...
1 she is my friend she is my friend
2 she goes to school at eight o'clock she goes to school at two o'clock,....
repetition in the new_sentences column is fine. I have tried to use np.where:
np.where(data.str.contains('o\'clock', regex=False, case=False, na=False), data["sentence"].replace()... )
but I do not know how to replace the word before 'o'clock
Thanking you in advance