2 回答

TA贡献1829条经验 获得超13个赞
你可能想要这个,假设你的意思是 14 行和 1 列:
pd.DataFrame(array).apply(list, axis=1)
如果您的意思是 50176 行和 1 列,则将其更改为:
pd.DataFrame(array).T.apply(list, axis=1)

TA贡献1803条经验 获得超3个赞
您可以将值转换为lists,但随后在 Pandas 中丢失了矢量化函数:
a = np.array(
[[219,220,221,32, 33, 34],
[154,152,149, 15, 15 ,15],
[205,202,192, 183, 183, 179],
[ 6, 7, 7, 24, 24, 25],
[239, 245,246, 101, 117,128],
[21, 44, 89, 120, 120,121]])
df = pd.DataFrame({'vectors':a.tolist()})
print (df)
vectors
0 [219, 220, 221, 32, 33, 34]
1 [154, 152, 149, 15, 15, 15]
2 [205, 202, 192, 183, 183, 179]
3 [6, 7, 7, 24, 24, 25]
4 [239, 245, 246, 101, 117, 128]
5 [21, 44, 89, 120, 120, 121]
所以更好的是将其转换为DataFrame:
df = pd.DataFrame(a)
print (df)
0 1 2 3 4 5
0 219 220 221 32 33 34
1 154 152 149 15 15 15
2 205 202 192 183 183 179
3 6 7 7 24 24 25
4 239 245 246 101 117 128
5 21 44 89 120 120 121
添加回答
举报