Split Strings into words with multiple word boundary delimiters

前端 未结 30 2707
既然无缘
既然无缘 2020-11-21 05:09

I think what I want to do is a fairly common task but I\'ve found no reference on the web. I have text with punctuation, and I want a list of the words.

\"H         


        
30条回答
  •  不思量自难忘°
    2020-11-21 05:47

    Instead of using a re module function re.split you can achieve the same result using the series.str.split method of pandas.

    First, create a series with the above string and then apply the method to the series.

    thestring = pd.Series("Hey, you - what are you doing here!?") thestring.str.split(pat = ',|-')

    parameter pat takes the delimiters and returns the split string as an array. Here the two delimiters are passed using a | (or operator). The output is as follows:

    [Hey, you , what are you doing here!?]

提交回复
热议问题