In [97]: df = pandas.Dataframe({'month': np.random.randint(0,11, 100), 'A': np.random.randn(100), 'B': np.random.randn(100)})In [98]: df.join(df.groupby('month')['A'].sum(), on='month', rsuffix='_r')Out[98]:A B month A_r0 -0.040710 0.182269 0 -0.3318161 -0.004867 0.642243 1 2.4482322 -0.162191 0.442338 4 2.0459093 -0.979875 1.367018 5 -2.7363994 -1.126198 0.338946 5 -2.7363995 -0.992209 -1.343258 1 2.4482326 -1.450310 0.021290 0 -0.3318167 -0.675345 -1.359915 9 2.722156
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)