0

我有一个基本的 Pandas DataFrame,例如:

In [2]: print(pd
                .DataFrame({
                            'a': pd.Index([1,2,3, 1,2,3]),
                            'b': pd.Categorical(['can','foo','bar', 'can','foo','bar']),
                            'c': pd.Series([7,8,9, 10,5,60]),
                            'd': pd.Series([7,8,9, 20,40,5])
                          })
                          .set_index('a')
                          .to_markdown())


|   a | b   |   c |   d |
|----:|:----|----:|----:|
|   1 | can |   7 |   7 |
|   2 | foo |   8 |   8 |
|   3 | bar |   9 |   9 |
|   1 | can |  10 |  20 |
|   2 | foo |   5 |  40 |
|   3 | bar |  60 |   5 |

我如何对每个索引的每个类别进行数学运算?- 举个例子,比如在索引处2我想乘以can.c除以foo.dcan.dbar.c?- 现在在 DataFrame 级别,我想要一个名为result每个索引存储的新列,结果是这样吗?

4

0 回答 0