gpt4 book ai didi

python - 在 pandas 系列中拆分为 '||'

转载 作者:太空宇宙 更新时间:2023-11-03 13:56:38 33 4
gpt4 key购买 nike

我想在 || 上 split

ser=pd.Series(['there a guy || I will have a bite || no can do','I can do || more'])
ser.str.split('||')

**我应该得到输出 [['那里有人','我要咬一口','不行'],['我能行','更多']]但我明白了

0    [, t, h, e, r, e, s,  , a,  , g, u, y,  , |, |...
1 [, I, , c, a, n, , d, o, , |, |, , m, o, r...
dtype: object

最佳答案

Double || 像正则表达式一样处理,因此需要通过 \ 转义此值:

a = ser.str.split('\|\|')
print (a)
0 [there a guy , I will have a bite , no can do]
1 [I can do , more]
dtype: object

关于python - 在 pandas 系列中拆分为 '||',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54804828/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com