日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python对象group函数_如何对groupby对象应用多个函数

發(fā)布時間:2024/10/8 python 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python对象group函数_如何对groupby对象应用多个函数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

這是一個很好的機會來強調(diào)熊貓0.20的變化之一

這是什么意思?

考慮數(shù)據(jù)幀dfdf = pd.DataFrame(dict(

A=np.tile([1, 2], 2).repeat(2),

B=np.repeat([1, 2], 2).repeat(2),

C=np.arange(8)

))

df

A B C

0 1 1 0

1 1 1 1

2 2 1 2

3 2 1 3

4 1 2 4

5 1 2 5

6 2 2 6

7 2 2 7

我們以前可以做的

^{pr2}$

我們的名字'f1'和{}被放在列標題中。但是,熊貓0.20我得到了這個//anaconda/envs/3.6/lib/python3.6/site-packages/ipykernel/__main__.py:1: FutureWarning: using a dict on a Series for aggregation

is deprecated and will be removed in a future version

if __name__ == '__main__':

那這是什么意思?如果我在沒有命名字典的情況下做兩個lambdas怎么辦?在df.groupby(['A', 'B']).C.agg([lambda x: x.size, lambda x: x.max()])

-

SpecificationError Traceback (most recent call last)

in ()

> 1 print(df.groupby(['A', 'B']).C.agg([lambda x: x.size, lambda x: x.max()]))

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/groupby.py in aggregate(self, func_or_funcs, *args, **kwargs)

2798 if hasattr(func_or_funcs, '__iter__'):

2799 ret = self._aggregate_multiple_funcs(func_or_funcs,

-> 2800 (_level or 0) + 1)

2801 else:

2802 cyfunc = self._is_cython_func(func_or_funcs)

//anaconda/envs/3.6/lib/python3.6/site-packages/pandas/core/groupby.py in _aggregate_multiple_funcs(self, arg, _level)

2863 if name in results:

2864 raise SpecificationError('Function names must be unique, '

-> 2865 'found multiple named %s' % name)

2866

2867 # reset the cache so that we

SpecificationError: Function names must be unique, found multiple named

pandas在名為''的多個列上出現(xiàn)錯誤

解決方案:命名函數(shù)def f1(x):

return x.size

def f2(x):

return x.max()

df.groupby(['A', 'B']).C.agg([f1, f2])

f1 f2

A B

1 1 2 1

2 2 5

2 1 2 3

2 2 7

總結(jié)

以上是生活随笔為你收集整理的python对象group函数_如何对groupby对象应用多个函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。