示例某支股票最长连续涨了多少交易日?
1 | import pandas as pd |
---|---|
2 | def iterate(col): |
3 | prev = 0; |
4 | res = 0; |
5 | val = 0; |
6 | for curr in col: |
7 | if curr – prev > 0: |
8 | res = 1; |
9 | else: |
10 | res = 0; |
11 | prev = curr; |
12 | if val < res: |
13 | val = res; |
14 | return val; |
15 | data = pd.read_excel('d:/stock.xlsx',sheet_name=0). sort_values('tradedate').groupby('company')['closeprice'].apply(iterate); |
1 | select max(continuousdays)-1 |
---|---|
2 | from (select count(*) continuousdays |
3 | from (select sum(changesign) over(order by tradedate) unrisedays |
4 | from (select tradedate, |
5 | case when closeprice>lag(closeprice) over(order by tradedate) |
6 | then 0 else 1 end changesign |
7 | from stock) ) |
8 | group by unrisedays) |
a | |
---|---|
1 | =stock.sort(tradedate) |
2 | =0 |
3 | =a1.max(a2=if(closeprice>closeprice[-1],a2 1,0)) |
vertica不支持存储过程,复杂业务逻辑只能用java写,代码冗长不易维护
excel种类多达44种,由java解析数据入库,开发周期长,硬编码难度高
全部44种excel解析由原来的32人天下降到6人天
每种excel解析代码量由100行变为3行
除代码量简短易维护外;脚本热部署即修改即生效