1

I have a dataframe (df) which is indexed by date

date             BBG.XSWX.KABN.S  BBG.XETR.TKA.S                        
2014-02-03       328.657522          19.083
2014-02-04       327.776510          18.809
2014-02-05       325.657202          18.337
2014-02-06       330.845170          18.690
2014-02-07       334.789668          19.153

Is there a way to remove any rows that have an indexed date which is older than say 2014-02-06, so I would have the resulting dataframe:

date             BBG.XSWX.KABN.S  BBG.XETR.TKA.S                       
2014-02-06       330.845170          18.690
2014-02-07       334.789668          19.153
1
  • 2
    the edits made by @users4393829 don't correct what is perfectly correct code by the OP i.e. the index (here 'date') can correctly be one level down! Commented Jun 30, 2015 at 7:53

2 Answers 2

5

you might want to try :

df.loc[df.index < '2014-02-06']

if your index is in datetime format then

df.loc[df.index < pd.to_datetime('2014-02-06')]  
Sign up to request clarification or add additional context in comments.

Comments

1

Pandas does allow row slicing:

>>> df['2014-02-06':]
            BBG.XSWX.KABN.S  BBG.XETR.TKA.S
date                                       
2014-02-06       330.845170          18.690
2014-02-07       334.789668          19.153

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.