My data is like this:
Name test1 test2 Count
Emp1 X,Y A 1
Emp2 X A,B,C 2
Emp3 Z C 3
<
I am just fix your code , since I do not recommend the method you unnesting the dataframe , you can check the answer here, there are multiple nice way.
df2 = df.test1.str.split(',').apply(pd.Series)
df2.index = df.set_index(['Name', 'Count']).index
df2=df2.stack().reset_index(['Name', 'Count'])
df3 = df.test2.str.split(',').apply(pd.Series)
df3.index = df.set_index(['Name', 'Count']).index
df3=df3.stack().reset_index(['Name', 'Count'])
merge
heredf2.merge(df3,on=['Name', 'Count'],how='outer')
Out[132]:
Name Count 0_x 0_y
0 Emp1 1 X A
1 Emp1 1 Y A
2 Emp2 2 X A
3 Emp2 2 X B
4 Emp2 2 X C
5 Emp3 3 Z C