简体   繁体   中英

Slice string colum in pandas

Guys i would like slice the column 'Delivey' in pandas line by line. How i do that?

Actual Data:

OF Delivery
BR1000 888000; 888001
BR1002 888002; 888003
BR1003 88804

New data:

OF Delivery
BR1000 888000
BR1000 888001
BR1002 888002
BR1002 888003
BR1003 88804

Thanks, Regards

Use str.split :

>>> df.assign(Delivery=df['Delivery'].str.split('; ')).explode('Delivery')
       OF Delivery
0  BR1000   888000
0  BR1000   888001
1  BR1002   888002
1  BR1002   888003
2  BR1003    88804

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM