我在运行程序时生成了一个变量,它的类型为系列,内容如下所示。可以看出test_prior
是一个系列,其中每个系列元素也是一个系列。如何检索这些元素系列并将它们保存到一个 numpy 数组中。或者,是否可以将其级数(即 test_prior
)保存到矩阵中?
type(test_prior)
pandas.core.series.Series
test_prior
0 [0.0032125000000000005, 0.003213987572590001, ...
1 [0.0037124999999999997, 0.00371353755063, 0.00...
2 [0.0003125, 0.0003170377214300023, 0.000321575...
3 [0.0048625, 0.004865587650670002, 0.0048686753...
4 [0.0020875, 0.0020882125347700003, 0.002088925...
...
195 [0.0010625, 0.0010631875335500003, 0.001063875...
196 [0.0009875, 0.0009895876018700012, 0.000991675...
197 [0.0024375, 0.0024401126274900013, 0.002442725...
198 [0.0022375, 0.0022403376384700015, 0.002243175...
199 [0.0005125, 0.000514487596990001, 0.0005164751...
Length: 200, dtype: object
答案 0 :(得分:1)
我认为您可以将 Series
转换为 DataFrame
,然后使用 explode
:
test_prior.to_frame().apply(lambda c: c.explode(), axis=1)
请注意,这仅在每行中的数组长度相同时才有效。但如果不是这种情况,那么将您的数据排列成两个维度似乎没有意义。