How to get required combinations from different rows of column in python

By marupav

I am trying to get the different required combinations out from dataframe column with few rows.It is something like below:
I have following values in one of the columns of my df
Oy
On
G1
G2
A1
A2
A3
A4
R1
R2
R3
L1
L2
A5
A6

Here oy,on belong to group 1,
G1,g2 – group 2,
A1 to a4 – group 3,
R1 to r3 – group 4,
L1,l2 – group 5,
A5,a6 – group 6

Now I am trying all the combinations from each value of the each group ranging from 1 value to all like below:

Oy
Oy g1
Oy g1 a1
Oy g1 a1 r1
Oy g1 a1 r1 l1
Oy g1 a1 r1 l1 a5

This will be for all possible combinations.note that within group combination is not desirable like g1 and g2 cannot come in same combination.

I know that this is possible with for loops with some if conditions.But looking for more efficient and elegant solution.

Please guide.

Thanks
Maddy

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273