Explanation:str.split accepts a pat (pattern) parameter: String or regular expression to split on. If not specified, split on whitespace. Using the fact we can pass a regular expression this becomes an easy task as [ ,]表示或,。在
另一种选择是使用' |,',或者如果可以有多个空格'\s+|,'
完整示例:
^{pr2}$
退货:
address Street Colony City
0 a,b,c a b c
1 a b c a b c
如果您确定regex中的逗号
^{pr 1}$,
或空白you could use:
Explanation:str.split accepts a pat (pattern) parameter: String or regular expression to split on. If not specified, split on whitespace. Using the fact we can pass a regular expression this becomes an easy task as
[ ,]
表示或
,
。在另一种选择是使用
' |,'
,或者如果可以有多个空格'\s+|,'
完整示例:
^{pr2}$退货:
试试这个
\W
将匹配任何非单词字符的字符。见docs实现这一点的一种方法是使用re.sub合并分隔符,然后在该分隔符上使用
str.split
来创建新列。在相关问题 更多 >
编程相关推荐