【发布时间】:2020-05-23 06:23:39
【问题描述】:
对于具有words 列的示例数据框,我想将每一行按llo 或lut 拆分为两列:words1 和words2。
words
0 helloworld
1 hellomadame
2 salutmonde
3 salutmadame
4 englishhelloworld
5 englishhellomadame
6 francaissalutmonde
7 francaissalutmadame
我怎样才能得到以下输出?谢谢。
words1 words2
0 hello world
1 hello madame
2 salut monde
3 salut madame
4 englishhello world
5 englishhello madame
6 francaissalut monde
7 francaissalut madame
我尝试使用df.words.str.split('llo | lut', expand=True),但没有成功。有人可以帮忙吗?非常感谢。
0
0 helloworld
1 hellomadame
2 salutmonde
3 salutmadame
4 englishhelloworld
5 englishhellomadame
6 francaissalutmonde
7 francaissalutmadame
【问题讨论】:
-
您可以通过调用
Series.str.split获得结果,请参阅this answer。
标签: regex python-3.x pandas dataframe split