3

I have a dataframe having column a,b,c. And column c has data in list datatype. So I want to unwind/unpacked/explode the each element of list as new row.

so, our input is like below.

   a  b             c
0  1  2          [1, {'k': 1}, 2]
1  3  2          [{'m': 2}, {'k': 2}, 2]

And our output should be like below.

   a  b          c
0  1  2          1
1  1  2          {'k': 1}
2  1  2          2
3  3  2          {'m': 2}
4  3  2          {'k': 2}
5  3  2          2

Sp, as you can in output, each element of list is in row and other column a and b values are repeating corresponding to list element

7
  • This is a dupe. Have you searched for it? Commented Jun 4, 2018 at 9:41
  • @AntonvBR what is dupe? Commented Jun 4, 2018 at 9:44
  • Can lists have variable size? Commented Jun 4, 2018 at 9:48
  • @YakymPirozhenko , we can create new column acc. to size of list in column c Commented Jun 4, 2018 at 9:53
  • 1
    @AntonvBR Thanks! it worked Commented Jun 6, 2018 at 11:16

1 Answer 1

1

The solutions from the questions linked in the comments are outdated. These days you can just:

df.explode('c')
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.