python - Convert DataFrame with index-OHLC data to index-O index-L index-H index-O (flatten OHLC data) -
i have dataframe looks that
open high low close volume (btc) volume (currency) weighted price date 2013-05-07 112.25000 114.00000 97.52 109.60013 139626.724860 14898971.673747 106.705731 2013-05-08 109.60013 116.77700 109.50 113.20000 61680.324704 6990518.957611 113.334665 2013-05-09 113.20000 113.71852 108.80 112.79900 26894.458204 3003068.410660 111.661235 2013-05-10 112.79900 122.50000 111.54 117.70000 77443.672681 9140709.083964 118.030418 2013-05-11 117.70000 118.74000 113.00 113.47000 25532.277740 2952016.798507 115.619015
i'm looking way transform kind of data to
index open index+1 low index+2 high index+3 open index+4 low index+5 high
so in sample should looks like
date 2013-05-07 00:00 112.25000 2013-05-07 08:00 97.52 2013-05-07 16:00 114.00000 2013-05-08 00:00 109.60013 2013-05-08 08:00 109.50 2013-05-08 16:00 116.77700 ...
my first idea resample dataframe
but first problem when i'm doing
df2 = df.resample('8h', how='mean')
i
open high low close volume (btc) volume (currency) weighted price 2013-05-07 00:00:00 112.25000 114.00000 97.52000 109.60013 139626.724860 14898971.673747 106.705731 2013-05-07 08:00:00 nan nan nan nan nan nan nan 2013-05-07 16:00:00 nan nan nan nan nan nan nan 2013-05-08 00:00:00 109.60013 116.77700 109.50000 113.20000 61680.324704 6990518.957611 113.334665 2013-05-08 08:00:00 nan nan nan nan nan nan nan 2013-05-08 16:00:00 nan nan nan nan nan nan nan 2013-05-09 00:00:00 113.20000 113.71852 108.80000 112.79900 26894.458204 3003068.410660 111.661235 ...
i need build column modulo 3 values
like this
modcol 2013-05-07 00:00:00 0 2013-05-07 08:00:00 1 2013-05-07 16:00:00 2 2013-05-08 00:00:00 0 2013-05-08 08:00:00 1 2013-05-08 16:00:00 2 2013-05-09 00:00:00 3 ...
so use np.where
make price column (open if mod==0, low if mod==1 , high if mod==2)
my problem if don't know how build modcol column
heres how create mod columns
in [1]: series(range(10)) out[1]: 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 dtype: int64 in [2]: series(range(10)) % 3 out[2]: 0 0 1 1 2 2 3 0 4 1 5 2 6 0 7 1 8 2 9 0 dtype: int64
Comments
Post a Comment