1 回答
TA贡献1828条经验 获得超13个赞
pd.concat
from functools import reduce
from operator import mul
from itertools import product
pd.concat({
k: reduce(mul, (d[c] for d, c in zip([d1, d2, d3], k)))
for k in product(d1, d2, d3)
}, axis=1)
D1 ... Unknown
E1 E2 ... E3 Unknown
S1 S2 S3 S4 Unknown S1 S2 S3 S4 Unknown ... S1 S2 S3 S4 Unknown S1 S2 S3 S4 Unknown
step 0 0.017291 0.009462 0.001587 0.006150 0.021445 0.005811 0.003180 0.000533 0.002067 0.007207 ... 0.005333 0.002918 0.000489 0.001897 0.006614 0.012394 0.006782 0.001138 0.004408 0.015372
step 1 0.011016 0.009085 0.011982 0.005702 0.007281 0.011148 0.009194 0.012126 0.005770 0.007369 ... 0.005306 0.004376 0.005771 0.002746 0.003507 0.006050 0.004989 0.006580 0.003131 0.003999
step 2 0.006153 0.007599 0.009829 0.007869 0.006028 0.007279 0.008990 0.011628 0.009309 0.007132 ... 0.007819 0.009656 0.012490 0.009999 0.007660 0.007069 0.008729 0.011291 0.009040 0.006925
step 3 0.005344 0.005939 0.006656 0.006304 0.004996 0.008189 0.009102 0.010200 0.009661 0.007656 ... 0.013315 0.014800 0.016585 0.015709 0.012449 0.006735 0.007485 0.008389 0.007945 0.006297
step 4 0.003607 0.005031 0.003798 0.006868 0.004510 0.004538 0.006329 0.004778 0.008639 0.005673 ... 0.006428 0.008966 0.006768 0.012239 0.008036 0.008175 0.011403 0.008608 0.015565 0.010220
[5 rows x 100 columns]
Numpy 广播和 pandas.MultiIndex.from_product
a = v1[:, :, None, None] * v2[:, None, :, None] * v3[:, None, None, :]
a = a.reshape(len(a), -1)
cols = pd.MultiIndex.from_product([d1, d2, d3])
pd.DataFrame(a, d1.index, cols)
添加回答
举报