예를 들어 .pipe()
GroupBy 개체에 대한 pandas documentation 메서드에서 동일한 람다를 허용하는 .apply()
메서드는 동일한 결과를 반환합니다.pandas : GroupBy .pipe() vs .apply()
In [195]: import numpy as np
In [196]: n = 1000
In [197]: df = pd.DataFrame({'Store': np.random.choice(['Store_1', 'Store_2'], n),
.....: 'Product': np.random.choice(['Product_1', 'Product_2', 'Product_3'], n),
.....: 'Revenue': (np.random.random(n)*50+10).round(2),
.....: 'Quantity': np.random.randint(1, 10, size=n)})
In [199]: (df.groupby(['Store', 'Product'])
.....: .pipe(lambda grp: grp.Revenue.sum()/grp.Quantity.sum())
.....: .unstack().round(2))
Out[199]:
Product Product_1 Product_2 Product_3
Store
Store_1 6.93 6.82 7.15
Store_2 6.69 6.64 6.77
나는 pipe
기능이 DataFrame 개체에 대한 apply
어떻게 다른지 볼 수 있지만 GROUPBY 개체 수 있습니다. 누구든지 pipe
을 사용하여 수행 할 수있는 작업에 대한 설명이나 예제가 있습니까? GroupBy의 경우 apply
이 아닌 경우?