我想分成以下几部分
11/27/2019 Sold $900,000 -6.2% Suzanne Freeze-Manning, Kevin Garvey
11/2/2019 Pending sale $959,000
进入
['11/27/2019', 'Sold', '$900,000', '-6.2%', 'Suzanne Freeze-Manning, Kevin Garvey']
['11/2/2019', 'Pending sale', '$959,000']
我试过使用regex,但是没有找到一个能够完成拆分的re.split()
组合,除了单词之间和逗号之后。你知道吗
我怎样才能做到这一点?你知道吗
你从哪里得到你的数据?是CSV吗?你能把分隔符改成逗号或别的什么吗?你知道吗
现在只能使用空格作为分隔符。你知道吗
例如:
注意,它切掉了字符串“苏珊·弗雷兹·曼宁,凯文·加维”
如果将选项卡用作分隔符,则可以轻松执行以下操作:
例如:
或者,如果您总是有5列数据,比如第一个字符串,您可以告诉它在第四次迭代后停止拼接。你知道吗
例如:
有关分隔符的详细信息,请参见https://docs.python.org/3.6/library/stdtypes.html#str.split。你知道吗
请尝试以下代码:
您可以使用此正则表达式,它查找前面没有字母或逗号,或者后面没有字母的空格:
Demo on regex101
在python中:
输出:
相关问题 更多 >
编程相关推荐