Reputation: 5152
Lets consider the following pandas DataFrame:
from pandas import Timestamp
dic={'volume': {('CSC', Timestamp('2016-08-06 00:00:00'), 'CSCF7'): 0,
('CSC', Timestamp('2016-08-07 00:00:00'), 'CSCG7'): 0,
('CSC', Timestamp('2016-08-08 00:00:00'), 'CSCH7'): 0,
('DA', Timestamp('2016-08-06 00:00:00'), 'DCF7'): 0,
('DA', Timestamp('2016-08-07 00:00:00'), 'DCG7'): 0,
('DA', Timestamp('2016-08-08 00:00:00'), 'DCH7'): 0,
('GF', Timestamp('2016-08-06 00:00:00'), 'GFF7'): 0,
('GF', Timestamp('2016-08-07 00:00:00'), 'GFH7'): 0,
('GF', Timestamp('2016-08-08 00:00:00'), 'GFJ7'): 0}}
import pandas as pd
df=pd.DataFrame(dic)
I would like to select certain rows using the boolean indexer:
here i want to select only the rows that are occuring at certain days of the week by using dayofweek!=5
.
How can i do that?
Upvotes: 0
Views: 251
Reputation: 76917
Using get_level_values
on df.index
you can
In [367]: df.loc[df.index.get_level_values(1).dayofweek != 5]
Out[367]:
volume
CSC 2016-08-07 CSCG7 0
2016-08-08 CSCH7 0
DA 2016-08-07 DCG7 0
2016-08-08 DCH7 0
GF 2016-08-07 GFH7 0
2016-08-08 GFJ7 0
Upvotes: 2