我有这种格式的pandas数据框:
idpso pso
0 [1.0290574795443606, 20000, 3.515564441680908] [0.041787490144988726, 20000, 11.214858293533325]
但我想把每个阵列分成几个细胞。有没有办法做到这一点?
答案 0 :(得分:2)
您可以将apply
与df=pd.DataFrame({'v1':[[1,2]],'v2':[[2,3]]})
df.stack().apply(pd.Series)
Out[638]:
0 1
0 v1 1 2
v2 2 3
TableB.ColumnA
答案 1 :(得分:2)
使用np.column_stack
考虑样本数据框
df = pd.DataFrame(dict(
idpso=[[1.0290, 20000, 3.5155]] * 3,
pso=[[0.0417, 20000, 11.2148]] * 3
))
df
idpso pso
0 [1.029, 20000, 3.5155] [0.0417, 20000, 11.2148]
1 [1.029, 20000, 3.5155] [0.0417, 20000, 11.2148]
2 [1.029, 20000, 3.5155] [0.0417, 20000, 11.2148]
pd.DataFrame(
np.column_stack(df.values.T.tolist())
)
0 1 2 3 4 5
0 1.029 20000.0 3.5155 0.0417 20000.0 11.2148
1 1.029 20000.0 3.5155 0.0417 20000.0 11.2148
2 1.029 20000.0 3.5155 0.0417 20000.0 11.2148
pd.concat
pd.concat({
k: pd.DataFrame(v.tolist())
for k, v in df.items()
}, axis=1)
idpso pso
0 1 2 0 1 2
0 1.029 20000 3.5155 0.0417 20000 11.2148
1 1.029 20000 3.5155 0.0417 20000 11.2148
2 1.029 20000 3.5155 0.0417 20000 11.2148