markov zain
markov zain

Reputation: 12925

How to convert ndarray to series in python

I have a ndarray like this one:

In [75]:
z_r
Out[75]:
array([[ 0.00909254],
       [ 0.02390291],
       [ 0.02998752]])

In here, I want to ask how to convert those things to series, the desired output is like this:

0   0.00909254
1   0.02390291
2   0.02998752

Upvotes: 26

Views: 46592

Answers (4)

sedge99
sedge99

Reputation: 11

Using list comprehension instead of map:

my_series = pd.Series([x[0] for x in z_r])

Upvotes: 0

Cohensius
Cohensius

Reputation: 545

pd.Series(my_ndarray)

no need to convert it first to a list then to series.

Upvotes: 13

Priagung Khusumanegara
Priagung Khusumanegara

Reputation: 500

You can use this one:

my_list = map(lambda x: x[0], z_r)
ser = pd.Series(my_list)
In [86]:
ser
Out[86]:
0      0.009093
1      0.023903
2      0.029988

Actually, your question is how to convert to series ^^

Upvotes: 32

Veedrac
Veedrac

Reputation: 60167

z_r.tolist()

                 

Upvotes: 5

Related Questions