如何根据定界符或词组拆分文本列行,并在每次拆分时保留名称?

时间:2019-04-23 00:33:02

标签: python dataframe split reshape

我有一个带有两列的电影评论数据帧:电影名称和评论。我想根据定界符将评论分为句子。或短语。然后,我想进行拆分查看,并将其下移一列,同时也将电影的名称下移一列。关键是要使基于每个句子或短语的情绪分析更加容易。

df[review] = df['review'].str.split('. or ? or ! or ?').reshape(0,1)

movie1.........Great movie...................................................................................................
movie1.........and Alot of action............................................ movie2.........What did I think?..........................................................................................
movie2..........It was a horrible...........................................................................................
movie2..........and waste of money!!..............................

1 个答案:

答案 0 :(得分:0)

df.Review.str.split('。')。apply(Series,1).stack()