python - Find lowest value of previous 3 days in pandas DataFrame -


i new python. sorry if question stupid..

i trying find lowest value of previous 3 days in time series.

e.g.

             price             low 1993-01-29   43.750000         nan 1993-02-01   43.968700         nan 1993-02-02   44.125000         43.750000 1993-02-03   42.375000         42.375000 1993-02-04   44.468700         42.375000 

i tried .shift(), .min() etc. none of them works. appreciated!

you can try this.

import pandas pd import numpy np  # data # =========================== np.random.seed(0) df = pd.dataframe(100+np.random.randn(100).cumsum(), index=pd.date_range('2015-01-01', periods=100, freq='b'), columns=['price']) df                  price 2015-01-01  101.7641 2015-01-02  102.1642 2015-01-05  103.1429 2015-01-06  105.3838 2015-01-07  107.2514 2015-01-08  106.2741 2015-01-09  107.2242 2015-01-12  107.0729 2015-01-13  106.9696 2015-01-14  107.3802 ...              ... 2015-05-07  100.1852 2015-05-08  101.4077 2015-05-11  101.6160 2015-05-12  102.5926 2015-05-13  102.9490 2015-05-14  103.6555 2015-05-15  103.6660 2015-05-18  105.4519 2015-05-19  105.5788 2015-05-20  105.9808  [100 rows x 1 columns]   # processing # =========================== pd.concat([df, df.shift(1), df.shift(2)], axis=1).dropna().max(axis=1)  2015-01-05    103.1429 2015-01-06    105.3838 2015-01-07    107.2514 2015-01-08    107.2514 2015-01-09    107.2514 2015-01-12    107.2242 2015-01-13    107.2242 2015-01-14    107.3802 2015-01-15    107.5243 2015-01-16    108.9785                 ...    2015-05-07    100.5884 2015-05-08    101.4077 2015-05-11    101.6160 2015-05-12    102.5926 2015-05-13    102.9490 2015-05-14    103.6555 2015-05-15    103.6660 2015-05-18    105.4519 2015-05-19    105.5788 2015-05-20    105.9808 freq: b, dtype: float64 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -