Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pb converting a list of pandas.Series into a numpy array of pandas.Series

I would like to convert a list of pandas.Series into a numpy array of pandas.Series. But when I call the array constructor, it also converting my Series.

>>> l = [Series([1,2,3]),Series([4,5,6])]
>>> np.array(l)
array([[1, 2, 3],
       [4, 5, 6]], dtype=int64)

My list is small (~10 elements), so for performances issues I would like to avoid to create a pandas.DataFrame. Is there an easy workaround?

Thanks in advance

like image 891
deubNippon Avatar asked Mar 10 '14 04:03

deubNippon


Video Answer


1 Answers

You should set the dtype of the array when you assign it:

l = [pd.Series([1,2,3]),pd.Series([4,5,6])]
np.array(l, dtype=pd.Series)

Though it is raises the question: why do you want an ndarray of series, and not an ndarray of the contents of the series?

like image 102
jme Avatar answered Oct 03 '22 22:10

jme