1 回答
TA贡献2037条经验 获得超6个赞
首先,您似乎有一个pd.Series而不是数据框。
进行设置:
x = [[2.0, 1246.0, 82.0, 43.0, 569.0, 46.0, 424.0],
[395.0, 2052.0, 1388.0, 8326.0, 5257.0, 176.0],
[4.0, 1.0, 13.0, 1409.0, 7742.0, 259.0, 1856.0],
[4.0, 87.0, 1595.0, 706.0, 2935.0, 6028.0, 442],
[45.0, 582.0, 124.0, 6530.0, 6548.0, 748.0, 61]]
s = pd.Series(x)
哪个产量
0 [2.0, 1246.0, 82.0, 43.0, 569.0, 46.0, 424.0]
1 [395.0, 2052.0, 1388.0, 8326.0, 5257.0, 176.0]
2 [4.0, 1.0, 13.0, 1409.0, 7742.0, 259.0, 1856.0]
3 [4.0, 87.0, 1595.0, 706.0, 2935.0, 6028.0, 442]
4 [45.0, 582.0, 124.0, 6530.0, 6548.0, 748.0, 61]
dtype: object
你有一个pd.Series数组。看起来你想把它弄平。在列表列表中使用默认构造函数会生成一个数据框,其中每个列表都被解释为一行:
df2 = pd.DataFrame(s.tolist())
0 1 2 3 4 5 6
0 2.0 1246.0 82.0 43.0 569.0 46.0 424.0
1 395.0 2052.0 1388.0 8326.0 5257.0 176.0 NaN
2 4.0 1.0 13.0 1409.0 7742.0 259.0 1856.0
3 4.0 87.0 1595.0 706.0 2935.0 6028.0 442.0
4 45.0 582.0 124.0 6530.0 6548.0 748.0 61.0
现在你可以得到底层np.array访问数据框.values
df2.values
array([[2.000e+00, 1.246e+03, 8.200e+01, 4.300e+01, 5.690e+02, 4.600e+01,
4.240e+02],
[3.950e+02, 2.052e+03, 1.388e+03, 8.326e+03, 5.257e+03, 1.760e+02,
nan],
[4.000e+00, 1.000e+00, 1.300e+01, 1.409e+03, 7.742e+03, 2.590e+02,
1.856e+03],
[4.000e+00, 8.700e+01, 1.595e+03, 7.060e+02, 2.935e+03, 6.028e+03,
4.420e+02],
[4.500e+01, 5.820e+02, 1.240e+02, 6.530e+03, 6.548e+03, 7.480e+02,
6.100e+01]])
添加回答
举报