dimanche 12 juin 2016

Select certain dates from Pandas dataframe


I am learning how to filter dates on a Pandas data frame and need some help with the following please. This is my original data frame (from this data):

data
Out[120]:
Open    High    Low Last    Volume  NumberOfTrades  BidVolume   AskVolume
Timestamp                               
2014-03-04 09:30:00 1783.50 1784.50 1783.50 1784.50 171 17  29  142
2014-03-04 09:31:00 1784.75 1785.75 1784.50 1785.25 28  21  10  18
2014-03-04 09:32:00 1785.00 1786.50 1785.00 1786.50 81  19  4   77
2014-03-04 09:33:00 1786.00 1786.00 1785.25 1785.25 41  14  8   33
2014-03-04 09:34:00 1785.00 1785.25 1784.75 1785.25 11  8   2   9
2014-03-04 09:35:00 1785.50 1786.75 1785.50 1785.75 49  27  13  36
2014-03-04 09:36:00 1786.00 1786.00 1785.25 1785.75 12  8   3   9
2014-03-04 09:37:00 1786.00 1786.25 1785.25 1785.25 15  8   10  5
2014-03-04 09:38:00 1785.50 1785.50 1784.75 1785.25 24  17  17  7

    data.dtypes
Out[118]:
Open              float64
High              float64
Low               float64
Last              float64
Volume              int64
NumberOfTrades      int64
BidVolume           int64
AskVolume           int64
dtype: object

I then resampled to 5 minute sections:

five_min = data.resample('5T').sum()

And look for the high volume days:

max_volume = five_min.Volume.at_time('9:30') > 65000

I then try to get the days high volume days as follows:

five_min.Volume = max_volume[max_volume == True]

for_high_vol = five_min.Volume.dropna()

for_high_vol

Timestamp
2014-03-21 09:30:00    True
2014-04-11 09:30:00    True
2014-04-16 09:30:00    True
2014-04-17 09:30:00    True
2014-07-18 09:30:00    True
2014-07-31 09:30:00    True
2014-09-19 09:30:00    True
2014-10-07 09:30:00    True
2014-10-10 09:30:00    True
2014-10-14 09:30:00    True
2014-10-15 09:30:00    True
2014-10-16 09:30:00    True
2014-10-17 09:30:00    True

I would like to use the index from "for_high_vol" to select all of the days from the original "data" Pandas dataframe.

Im sure there are much better was to approach this so can someone please show me the simplest way to do this?


Aucun commentaire:

Enregistrer un commentaire