Skip to content
Advertisement

Pandas how to explode several items of list for each new row

I have a dataframe:

JavaScript

I want explode it such that every 3 elements from each list in the column l will be a new row, and the column for the triplet index within the original list. So I will get:

JavaScript

What is the best way to do so?

Advertisement

Answer

Break list element into chunks first and then explode:

JavaScript

If you need the index column:

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