如何在python中将ndarray转换为系列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30564172/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:39:11  来源:igfitidea点击:

How to convert ndarray to series in python

pythonpandasmultidimensional-array

提问by markov zain

I have a ndarraylike this one:

我有一个ndarray这样的:

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:

在这里,我想问一下如何将这些东西转换为series,所需的输出是这样的:

0   0.00909254
1   0.02390291
2   0.02998752

采纳答案by Priagung Khusumanegara

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 ^^

其实,你的问题是如何转换为系列^^

回答by Veedrac

z_r.tolist()

                 

                 

回答by Cohensius

pd.Series(my_ndarray)

pd.Series(my_ndarray)

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

无需先将其转换为列表,然后再转换为系列。