Python:将2D numpy数组转换为熊猫系列

问题描述 投票:1回答:1

我有一个如下所示的2D numpy数组,我想将其存储在pandas列中。我无法在搜索的任何地方找到相关示例。请帮助。谢谢!

#2D array
[[0,2],[2,3]]

#Expected output is pandas dataframe with single column :
[0,2]
[2,3]
python pandas numpy
1个回答
1
投票

IIUC使用:

a = np.array([[0,2],[2,3]])
s = pd.Series(a.tolist())
print (s)
0    [0, 2]
1    [2, 3]
dtype: object
© www.soinside.com 2019 - 2024. All rights reserved.