链接aggreggation程序
问题描述:
我有以下代码:链接aggreggation程序
myData_agg = myData.groupby("Customer")["PurchAmount"].sum()
myData_agg.loc[myData_agg>=100,]
我可以写一个程序代码? 谢谢!
答
选项之一:
链它们与[]
和lambda
表达式:
myData.groupby("Customer")["PurchAmount"].sum()[lambda x: x >= 100]
方法二:
使用compress
方法:
myData.groupby("Customer")["PurchAmount"].sum().compress(lambda x: x >= 100)
方案三:
使用pipe
:
myData.groupby("Customer")["PurchAmount"].sum().pipe(lambda x: x[x >= 100])