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
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With