Skip to content
Advertisement

Pandas – Duplicate Rows and Slice String

I’m trying to create duplicate rows during a dataframe on conditions.

For example, I have this Dataframe.

JavaScript
JavaScript

And I would like to get the following output:

JavaScript

Advertisement

Answer

For pandas 0.25+ is possible use DataFrame.explode with splitted values by Series.str.split and for remark column list comprehension with filtering:

JavaScript

And we get the following result:

JavaScript
Advertisement