【发布时间】:2021-03-04 08:46:11
【问题描述】:
除非第二个单词是小写,否则如何用第一个空格分割长字符串?
df col
0 Apple The fruit. 20 Banana tree A fruit. 30 Carrot A Vegetable. 40
预期输出:
df
fruit definition page
0 Apple The fruit. 20
1 Banana tree A fruit. 30
2 Carrot A Vegetable. 40
df.col.str.split('(\d+)').explode()
0 Apple The fruit.
0 20
0 Banana tree A fruit.
0 30
0 Carrot A Vegetable.
0 40
df.col.split(".", expand = True)
【问题讨论】:
标签: python python-3.x regex pandas