Change OHLC resampling code to obsolete warning

Question:

When working with market data and re-sampling intraday data on daily timeframes as follows:

ohlc_dict = { 'Open':'first', 'High':'max', 'Low':'min', 'Last': 'last', 'Volume': 'sum'} data.resample('1D',how=ohlc_dict).tail().dropna() Open High Last Low Volume Timestamp 2016-12-27 163.55 164.18 164.11 163.55 144793.00 2016-12-28 164.18 164.33 164.22 163.89 215288.00 2016-12-29 164.44 164.65 164.49 164.27 245538.00 2016-12-30 164.55 164.56 164.18 164.09 286847.00 

Which seems to give me the result I need (still need to check) ...

I get the following warning:

 FutureWarning: how in .resample() is deprecated the new syntax is .resample(...)..apply(<func>) 

Question:

How would this replicated resample code be created using the new syntax to align with current best practice using apply ?

What I tried:

Just using the data ['Low'] as an example:

 def ohlc (df): return df['Low'].min() data.resample('1D').dropna().apply(ohlc,axis=1).tail(2) Timestamp 2016-12-29 164.45 2016-12-30 164.26 dtype: float64 

It does not give me the same results, and I'm not sure where to apply .

Here is a piece of data to check this out if necessary:

thanks

+8
python pandas
source share
1 answer

.resample() works like groupby , so you can pass this dictionary to resample().agg() :

 df.resample('1D').agg(ohlc_dict).tail().dropna() Out: Volume Last High Open Low Timestamp 2016-12-27 144793.0 164.11 164.18 163.55 163.55 2016-12-28 215288.0 164.22 164.33 164.18 163.89 2016-12-29 245538.0 164.49 164.65 164.44 164.27 2016-12-30 286847.0 164.18 164.56 164.55 164.09 
+7
source share

All Articles