Skip to content
Advertisement

Split column to multiple columns by another column value (complicated separator)

  1. I have dataframe like:
JavaScript

len of column1 value may be different – from 2 to 5 words, so split with space not an option.

JavaScript
  1. Output should be like:
JavaScript

That topic – How to split a dataframe string column into two columns? – didn’t help coz of separator

UPD. Left “side” may have 2-5 words – and right side too.

Advertisement

Answer

option 1

Splitting on spaces is an option, if you have a single word for the last two columns. Use rsplit:

JavaScript

output:

JavaScript

NB. this doesn’t work with the updated example

option 2

Alternatively, to split on the provided delimiter:

JavaScript

output:

JavaScript

option 3

Finally, if you have many time the same delimiters and many rows, it might be worth using vectorial splitting per group:

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement