美文网首页Py100Skills
[Py018] pandas transform

[Py018] pandas transform

作者: 安哥生个信 | 来源:发表于2018-11-13 12:13 被阅读15次

原文见https://www.jianshu.com/p/509d7b97088c

aggregation会返回数据的缩减版本,而transformation输出的形状和输入一致

In[18]: df
Out[18]: 
   one  two  three  four
a    0    1      2     3
a    4    5      6     7
b    8    9     10    11
d   12   13     14    15
In[19]: df.groupby(df.index).aggregate(sum) 
Out[19]: 
   one  two  three  four
a    4    6      8    10
b    8    9     10    11
d   12   13     14    15
In[20]: df.groupby(df.index).transform(sum)
Out[20]: 
   one  two  three  four
a    4    6      8    10
a    4    6      8    10
b    8    9     10    11
d   12   13     14    15

相关文章

网友评论

    本文标题:[Py018] pandas transform

    本文链接:https://www.haomeiwen.com/subject/smwkfqtx.html