【对比Python】分组子集迭代循环

任务:计算各销售员几月份销售额达到50万。

Python

1 import pandas as pd
2 sale_file = "E:/txt/orders_i.csv"
3 sale_data = pd.read_csv(sale_file,sep='\t')
4 sale_g = sale_data.groupby('sellerid')
5 breach50_list = []
6 for index,group in sale_g:
7     amount=0
8     group = group.sort_values('month')
9     for row in group.itertuples():
10         amount+=getattr(row, 'amount')
11         if amount>=500000:
12             breach50_list.append([index,getattr(row, 'month'),])
13             break
14 breach50_df = pd.DataFrame(breach50_list,columns=['sellerid','month'])
15 print(breach50_df)

集算器

  A  
1 E:/txt/orders_i.csv  
2 =file(A1).import@t()  
3 =A2.group(sellerid;(~.iterate((x=month,~~+amount),0,~~>500000),x):breach50)  

集算器保留分组子集,使用迭代函数实现迭代。