【问题标题】:split strings in a cell into different row, pandas [closed]将单元格中的字符串拆分为不同的行,pandas [关闭]
【发布时间】:2021-11-20 04:27:00
【问题描述】:

我需要在 pandas 数据框中将这个单元格拆分为不同的行,基本上是拆分字符串,但忽略引号内的逗号。

'one two three', 'don't split, this'

输出如下:

'one two three'
'don't split, this'

提前致谢

【问题讨论】:

  • 完整字符串的类型是什么?它是一个列表,还是一个字符串本身?请给出一个正确(完整)的例子,不仅仅是几个字符串,而是一个显示问题的实际数据框。

标签: python regex pandas


【解决方案1】:

为什么不直接使用:

df['col'].str.split(r"(?<=')[,(\s|)](?=')")

或者如果逗号后面总是有空格,那么:

s.str.split(r"(?<='), (?=')")

【讨论】:

    猜你喜欢
    • 2014-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多