0

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)

enter image description here

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?

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

My answer was exact same. You are the fastest finger now. +1

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.