对两个系列的数组操作

Array manipulation to two series

我有一个如下所示的数组:

array([[ 0.        ,  0.        ],
       [ 0.        ,  0.        ],
       [ 0.        ,  0.        ],
       [ 2.94642408, 25.7209404 ],
       [ 0.79932443,  6.12162428],
       [ 1.89396598, 14.46259769]])

我想将其更改为两个系列,其中第一个系列的元素在左侧,第二个系列的元素在右侧。理想情况下,最后我想将结果系列添加到数据框中。

我该怎么做?

使用切片和pd.Series构造函数:

s1 = pd.Series(a[:, 0])
s2 = pd.Series(a[:, 1])

如果你真的想要系列,请按照 j1-lee 的回答。

既然你提到你最终想要一个数据框,你真的不需要一系列的中间步骤。

如果你只是把你的数组(我们称之为arr)如下

pd.DataFrame(arr, columns=['series_1','series_2'])

   series_1   series_2
0  0.000000   0.000000
1  0.000000   0.000000
2  0.000000   0.000000
3  2.946424  25.720940
4  0.799324   6.121624
5  1.893966  14.462598