Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Split a column value based on condition

I am trying to split a column based on whether a slash(‘/) is present in the cell within that column. Not all cells contain slashes. Most only contain 3 letters (e.g.’ABC’).

I am trying to avoid for loops since they affect performance. I have tried the following code:

df.column.split('/',expand=True)

I get the following outut:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

AttributeError: 'Series' object has no attribute 'split'

>Solution :

Almost there:

df.column.str.split('/',expand=True)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading