2

Ok, this is an easy one, I hope.

Using Pandas, I have a Series of 100 equal length Numpy arrays each with 30000 elements. I'd like to quickly transpose them into a series of 30000 arrays with 100 elements.

I of course can do it with list comprehensions or pulling the arrays but is there an efficient Pandas way to do it? Thanks!

UPDATE:

As per the request by @Alexander to make this a better example, here is some toy data.

import pandas
s1 = pandas.Series([np.array(range(10)) for i in range(10)])

And what I want returned in this example is:

s2 = pandas.Series([np.ones(10)*i for i in range(10)])

That is, an element-wise transpose of a Series of arrays into a new Series of arrays. Thanks!

Joe Flip
  • 1,076
  • 4
  • 21
  • 37
  • 1
    100 arrays, each with 30k elements. Isn't that a 30k x 100 matrix? See this question on asking good questions: How to make good reproducible pandas examples http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – Alexander Sep 01 '15 at 05:19

1 Answers1

1

Ok, this works actually. Any one have a more efficient solution?

pandas.Series(np.asarray(s1.tolist()).T.tolist())
Joe Flip
  • 1,076
  • 4
  • 21
  • 37