Skip to content
Advertisement

How to split AFTER underscore in Python

I’ve seen a lot of threads that say how to split based on an underscore, but how can we split a string where the split is done after the underscore.

So let’s say I have a pandas dataframe with one column:

JavaScript

how can I achieve the following output?

JavaScript

Thanks in advance.

Advertisement

Answer

You can split with the _ as a separator and then add again the _ to the id string:

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