从评论列中提取句子并将其添加到新列中,为每个新句子重复其他行
Extract Sentences from review column and adding it in a new column, repeating the other rows for each new sentence
我有 3 列。评论、日期和评论评级。我想将评论拆分成句子并在新列下添加句子,但其他行应根据句子数量重复。
例如
Date Review_Rating Review Sentence
12-02-2021 5 ram is good. ram is intelligent ram is good.
12-02-2021 5 ram is good. ram is intelligent ram is intelligent
IIUC,可以使用assign
和explode
:
>>> df
Date Review_Rating Review
0 12-02-2021 5 ram is good. ram is intelligent
>>> df.assign(Sentence=df['Review'].str.split(r'\.\s*')).explode('Sentence')
Date Review_Rating Review Sentence
0 12-02-2021 5 ram is good. ram is intelligent ram is good
0 12-02-2021 5 ram is good. ram is intelligent ram is intelligent
我有 3 列。评论、日期和评论评级。我想将评论拆分成句子并在新列下添加句子,但其他行应根据句子数量重复。
例如
Date Review_Rating Review Sentence
12-02-2021 5 ram is good. ram is intelligent ram is good.
12-02-2021 5 ram is good. ram is intelligent ram is intelligent
IIUC,可以使用assign
和explode
:
>>> df
Date Review_Rating Review
0 12-02-2021 5 ram is good. ram is intelligent
>>> df.assign(Sentence=df['Review'].str.split(r'\.\s*')).explode('Sentence')
Date Review_Rating Review Sentence
0 12-02-2021 5 ram is good. ram is intelligent ram is good
0 12-02-2021 5 ram is good. ram is intelligent ram is intelligent