回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我是新来的熊猫,我正在努力掌握多指标数学。。。在</p>
<p>假设我们有一个包含2D列和2D行的pandas数据帧,在这个示例中,我们如何添加一个值等于的“sub column”<code>('ALPHA', 'gamma')</code>
<code>(same d1, same d2, 'ALPHA', 'alpha') +
(same d1, d2-1, 'BETA', 'alpha')</code>,即{<cd3>}是10+2?在</p>
<pre><code>ridx = pd.MultiIndex.from_tuples([('A',1),('A',2),('A',3),('B',1),('B',2),('B',3),('C',1),('C',2),('C',3)], names=['d1', 'd2'])
cidx = pd.MultiIndex.from_tuples([('ALPHA','alpha'),('ALPHA','beta'),('BETA','alpha'),('BETA','beta')], names=['d3', 'd4'])
dfmix = pd.DataFrame([(0,1,2,3),(10,11,12,13),(20,21,22,23),
(30,31,32,33),(40,41,42,43),(50,51,52,53),
(60,61,62,63),(70,71,72,73),(80,81,82,83),
], index=ridx, columns=cidx)
dfmix
</code></pre>
<p><a href="https://i.stack.imgur.com/pmfc2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pmfc2.png" alt="dataframe"/></a></p>