1
keroppi OP 我目前自己写的代码(第 2 个要求还没搞)
``` for i in range(1, end_num): df['prev_row'] = df['total'].shift(i) df['range_compare_result'] = df['total'].lt(df['prev_row']) del df['prev_row'] # end for ``` |
2
necomancer 2021-11-11 00:38:01 +08:00
In [2]: ret = []
In [2]: for i in range(7, a.shape[0]+1): ...: m = np.argmin(a[i-7:i]) +i -7 ...: ret.append((m, a[m], m==i-1)) ...: In [3]: ret Out[3]: [(4, 0.1070058697941636, False), # (绝对索引,值,当日是否为当周(前 7 日)最低) (4, 0.1070058697941636, False), (4, 0.1070058697941636, False), (4, 0.1070058697941636, False), (4, 0.1070058697941636, False), (7, 0.38082268305528855, False), (7, 0.38082268305528855, False), (13, 0.3198102115371413, True), (13, 0.3198102115371413, False), (15, 0.26007158139013975, True), (15, 0.26007158139013975, False), (15, 0.26007158139013975, False), (18, 0.1774755070886418, True), (18, 0.1774755070886418, False)] In [4]: a Out[4]: array([0.59171944, 0.95287085, 0.56036765, 0.91771266, 0.10700587, 0.67920182, 0.40034268, 0.38082268, 0.81140219, 0.78271362, 0.43178875, 0.7328393 , 0.93324926, 0.31981021, 0.74938937, 0.26007158, 0.33768583, 0.78881252, 0.17747551, 0.27862649]) |
3
ThirdFlame 2021-11-11 08:53:46 +08:00
用 query
|
4
dongxiao 2021-11-11 09:58:45 +08:00 1
pandas 先 rolling 后 聚合,比如以每一天与过去 7 天做比较:
1. dataframe.rolling("7d").min() == dataframe 2. dataframe.rolling("7d").min() |
5
princelai 2021-11-11 10:07:40 +08:00
```
df = pd.DataFrame(np.random.randint(10,50,30),index=pd.date_range(start='2021-01-01',periods=30),columns=["sales"]) df['pass_min'] = df.rolling(window=7, min_periods=1)['sales'].min() df['is_min'] = df.sales==df.pass_min ``` 这样吗? |
6
Nehcknarf 2021-11-12 09:23:58 +08:00 1
滑动窗口 rolling().min()
和 query 判等应该可以解决 |
7
UN2758 2021-11-12 16:57:32 +08:00
4 ,6 说得对
|
8
shm7 2021-11-21 18:20:47 +08:00
学习了,还有 rooling 这个方法
|