当我运行这样的代码时:
import pandas as pd
A = pd.DataFrame([('a', -1.374201, 35),
('b', 1.415697, 29),
('a', 0.233841, 18),
('b', 1.550599, 30),
('a', -0.178370, 63),
('b', -1.235956, 42),
('a', 0.088046, 2),
('b', 0.074238, 84)], columns='key value other'.split())
B = A.groupby('key')['value'].mean()
C = pd.DataFrame([('a', 0.469924, 44),
('b', 1.231064, 68),
('a', -0.979462, 73),
('b', 0.322454, 97)], columns='key value other'.split())
D = C.set_index('key')
D['value'] -= B
...最后一行因错误而失败:
Exception: Reindexing only valid with uniquely valued Index objects
我究竟做错了什么?