I have this data set, in which there is a uid field which is a list of integers, and another array which is a list of booleans that corresponds to the uid fields. I'd like to turn this array records into long records instead, exploding on /2/ aligned columns.
name uid is_left colC colD colE ...
record01 [885] [True] .. .. .. ...
record02 [981] [False] .. .. .. ...
record03 [713, 981] [False, True] .. .. .. ...
record04 [713] [True] .. .. .. ...
record05 [126] [True] .. .. .. ...
I understand that for pandas 1.3.0 I can use this syntax to multi-column explode:
df.explode(['uid', 'is_left'])
However, I am stuck on a lower version, 1.25.0 and cannot use the 1.3.0 multi column explode simple syntax. What is the correct way to go from what I have to:
name uid is_left colC colD colE ...
record01 885 True .. .. .. ...
record02 981 False .. .. .. ...
record03 713 False .. .. .. ...
record03 981 True .. .. .. ...
record04 713 True .. .. .. ...
record05 126 True .. .. .. ...
You can see record03
now has 2 entries, one for (713, False)
and one for (981, True)
, and it is NOT the Cartesian explosion you'd get from applying explode twice:
(713, False)
(713, True)
(981, False)
(981, True)
References: