Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split on '||' in pandas series

I m trying to split on ||

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

**I should get output as [['there a guy','I will have a bite','no can do'],['I can do','more']] but I m getting this

0    [, t, h, e, r, e, s,  , a,  , g, u, y,  , |, |...
1    [, I,  , c, a, n,  , d, o,  , |, |,  , m, o, r...
dtype: object
like image 520
Prasun Jain Avatar asked Dec 14 '25 04:12

Prasun Jain


1 Answers

Double || is processing like regex, so need escape this values by \:

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
like image 153
jezrael Avatar answered Dec 15 '25 17:12

jezrael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!