I want to use cummin but it doesnt work, It shows zero, cummax work well.
my code:
JavaScript
x
5
1
df = pd.DataFrame(df, columns=['symbol', 'timestamp', 'open', 'high', 'low', 'close', 'volume'])
2
df["min_Close"] = df.close.shift(fill_value=0).cummin()
3
df["max_Close"] = df.close.shift(fill_value=0).cummax()
4
print(df)
5
original df:
JavaScript
1
8
1
symbol timestamp open high low close volume
2
0 AAVEUSDT 1663186500000 81.70 81.90 81.65 81.80 405.54
3
1 AAVEUSDT 1663186800000 81.80 81.85 81.70 81.75 233.11
4
2 AAVEUSDT 1663187100000 81.75 82.05 81.75 81.75 346.30
5
3 AAVEUSDT 1663187400000 81.75 81.90 81.60 81.90 126.11
6
4 AAVEUSDT 1663187700000 81.90 81.95 81.70 81.75 260.90
7
5 AAVEUSDT 1663188000000 81.75 81.75 81.60 81.65 274.26
8
my result :
JavaScript
1
8
1
symbol timestamp open high low close volume min_Close max_Close
2
0 AAVEUSDT 1663186500000 81.70 81.90 81.65 81.80 405.54 0.0 0.00
3
1 AAVEUSDT 1663186800000 81.80 81.85 81.70 81.75 233.11 0.0 81.80
4
2 AAVEUSDT 1663187100000 81.75 82.05 81.75 81.75 346.30 0.0 81.80
5
3 AAVEUSDT 1663187400000 81.75 81.90 81.60 81.90 126.11 0.0 81.80
6
4 AAVEUSDT 1663187700000 81.90 81.95 81.70 81.75 260.90 0.0 81.90
7
5 AAVEUSDT 1663188000000 81.75 81.75 81.60 81.65 274.26 0.0 81.90
8
Advertisement
Answer
It is expected, because after shift first value is 0
, so after cummin
is here always 0
(until negative value):
JavaScript
1
9
1
print (df.close.shift(fill_value=0))
2
0 0.00
3
1 81.80
4
2 81.75
5
3 81.75
6
4 81.90
7
5 81.75
8
Name: close, dtype: float64
9
Remove fill_value=0
for NaN
instead 0
for first value in Series.shift
, last if necessary replace first missing value by Series.fillna
:
JavaScript
1
19
19
1
print (df.close.shift())
2
0 NaN
3
1 81.80
4
2 81.75
5
3 81.75
6
4 81.90
7
5 81.75
8
Name: close, dtype: float64
9
10
df["min_Close"] = df.close.shift().cummin().fillna(0)
11
print (df)
12
symbol timestamp open high low close volume min_Close
13
0 AAVEUSDT 1663186500000 81.70 81.90 81.65 81.80 405.54 0.00
14
1 AAVEUSDT 1663186800000 81.80 81.85 81.70 81.75 233.11 81.80
15
2 AAVEUSDT 1663187100000 81.75 82.05 81.75 81.75 346.30 81.75
16
3 AAVEUSDT 1663187400000 81.75 81.90 81.60 81.90 126.11 81.75
17
4 AAVEUSDT 1663187700000 81.90 81.95 81.70 81.75 260.90 81.75
18
5 AAVEUSDT 1663188000000 81.75 81.75 81.60 81.65 274.26 81.75
19