pandas - PYTHON: Creating a dataframe of permutations from a list of tuples -


i presently trying create massive table of permuted values.

loca = [1, 2, 3] locb = [4, 5, 6] locc = [7, 8, 9] 

within 'loc' values permuted. each value in 'loc' different population ('pop1', 'pop2', 'pop3'). far have have been able form massive list of tuples combines every within 'loc' rearrangement every between 'loc' rearrangement.

perma = list(itr.permutations(loca, 3)) permb = list(itr.permutations(locb, 3)) permc = list(itr.permutations(locc, 3)) permabc = list(itr.product(perma,permb,permc))  permabc [((1, 2, 3), (4, 5, 6), (7, 8, 9)), ((1, 2, 3), (4, 5, 6), (7, 9, 8)), ((1, 2, 3), (4, 5, 6), (8, 7, 9)),      ... etc etc...  ((3, 2, 1), (6, 5, 4), (8, 9, 7)), ((3, 2, 1), (6, 5, 4), (9, 7, 8)), ((3, 2, 1), (6, 5, 4), (9, 8, 7))]    

i have been trying pandas dataframe, having trouble iterating through list of tuples dataframe. :(

ideal format:

loc  pop1  pop2  pop3    1     2     3    | b    4     5     6    |>>>> permabc[0] c    7     8     9    |  ... etc etc ...     3     2     1    | b    6     5     4    |>>>> permabc[215] c    9     8     7    | 

my problem getting list of tuples dataframe. need every combination possible of 'loc'. e.g. possible rearrangements of 'loca' rearrangements of 'locb' rearrangements of 'locc'.

to put perspective, particular permutation each population, i'll need make calculations. sake of argument, in above, 'perabc[0]' , 'permabc[215],' mean 'pop1' 4 , 6 respectively.

i'm not sure how on fly , @ level of coding easier anchor things dataframe can manipulate. have tried playing using indexes pull out population specific info given permutation in 'permabc', e.g.

for item in permabc[0]:     print item[0]     1     4     7 

which works, using method isn't feasible because can't functions on them; returns typeerror "'int' object not iterable".

cheers.

if trouble related performance or memory:

i think problem take generator itr.permutations , convert whole thing list:

permc = list(itr.permutations(locc, 3)) 

thereby destroying whole point of generator.

you should process each permutation generated, throw away. decrease memory profile dramatically , speed computation.

for pair in itr.permutations(locc, 3):     # stuff 

in above code, each pair exist duration of iteration, after next pair generated.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -