Reputation: 8015
I have a variable generated while running a program, which has the series type, and contents shown as follows. It can be seen that test_prior
is a series, where each series element is a also a series. How to retrieve these element series and save them into a numpy array. Or, is that possible to save this whose series, i.e., test_prior
, into a matrix?
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
Upvotes: 0
Views: 82
Reputation: 1439
I think you can convert the Series
to a DataFrame
and then use explode
:
test_prior.to_frame().apply(lambda c: c.explode(), axis=1)
Note that this will only work if the array in each row has the same length. But if this was not the case, then arranging your data into two dimensions wouldn't seem to make sense.
Upvotes: 1