Johan Nilssons Lifestream

Pandas: Pairwise concatenation of column vectors

I'm working with a frame like

df = pd.DataFrame({

and I want to manipulate it so that the columns are pairwise permutations of the current columns e.g. all columns are now 10 elements long and for example column 'G1:G2' would have column 'G2' appended to column 'G1'. I have attached a mock-up pic. Note that the pic has named indices unlike the above example code. I can work with or without the indices.

How could I approach this? I can make a function to act on each column, but I think the function would have to return a data frame made by concatenation with all other columns. Not sure what that would look like.

enter image description here

via Stack Overflow

blog comments powered by Disqus
Get the source for phplifestream at Github