Pb converts pandas.Series list to numpy pandas.Series array

I would like to convert the pandas.Series list to a numpy pandas.Series array. But when I call the array constructor, it also converts 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 items), so for performance issues ( https://stackoverflow.com/questions/22212777/python-pandas-small-series-performances?noredirect=1#comment33725521_22212777 ) I would like to avoid creating pandas. DataFrame Is there an easy way?

Thanks in advance

+8
python arrays numpy pandas
source share
1 answer

You must set the dtype array when it is assigned:

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

Although the question arises: why do you want ndarray from the series, and not ndarray from the contents of the series?

+4
source share

All Articles