给出一个列表列表(或数组的numpy数组):
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]])
如何在每行中创建一个带有数组的Pandas系列?
0 [0, 0, 0, ..., 0, 0, 0]
1 [0, 0, 0, ..., 0, 0, 0]
...
999 [0, 0, 0, ..., 0, 0, 0]
1000 [0, 0, 0, ..., 0, 0, 0]
df['my_array'] = pd.Series(my_array_of_arrays)
Traceback (most recent call last)
...
Exception: Data must be 1-dimensional
答案 0 :(得分:1)
转换为列表,以便将每个元素存储为系列中的数组:
string.matches("")
你可以看到该元素仍然是一个数组:
In [112]:
a = np.array([[0,1,2],[2,3,5]])
Out[112]:
array([[0, 1, 2],
[2, 3, 5]])
In [114]:
pd.Series(list(a))
Out[114]:
0 [0, 1, 2]
1 [2, 3, 5]
dtype: object