【对比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) |
集算器保留分组子集,使用迭代函数实现迭代。