Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following data df_matrix, level_1 and level_2 are the multi-index:

|level_1|level_2|value_1|value_2|value_3|
|-------|-------|-------|-------|-------|
|a      |w      |1      |2      |3      |
|       |y      |4      |5      |6      |
|       |y      |4      |5      |6      |
|       |z      |7      |8      |9      |
|b      |w      |11     |21     |31     |
|       |x      |41     |51     |61     |
|       |y      |41     |51     |61     |
|       |z      |71     |81     |91     |

and df_column, id is the index:

id value
value_1 0.1
value_2 0.2
value_3 0.3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
517 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can just use the dot function directly; it will be aligned on the common index; after that it is a straightforward unstack, droplevel and rename.

(
    df_matrix.dot(df_column)
    .unstack()
    .droplevel(0, axis=1)
    .rename_axis(index=None, columns=None)
)

     w       x       y      z
a   1.4     3.2      3.2    5.0
b   14.6    32.6    32.6    50.6

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...