I have a dataframe df
as
df
col1 act_id col2
--------------------
0 40;30;30 act1 A;B;C
1 25;50;25 act2 D;E;F
2 70;30 act3 G;H
I want to break each record in such a way that values in column col1
and col2
explode into multiple rows but such that the first value in col1
after splitting upon ';'
corresponds to the first value in col2
after splitting upon ';'
. So my desired_df
should look like this:
desired_df
col1 act_id col2
---------------
0 40 act1 A
1 30 act1 B
2 30 act1 C
3 25 act2 D
4 50 act2 E
5 25 act2 F
6 70 act3 G
7 30 act3 H
NOTE: this is not the same as Split (explode) pandas dataframe string entry to separate rows as here the exploding/splitting of one record is not just across one column but the need is to split or explode one row into multiple rows, in two columns simultaneously.
Any help is appreciated. Thanks