21

From the following DataFrame with datetime index

                                       'A'
2015-02-17 14:31:00+00:00           127.2801
2015-02-17 14:32:00+00:00           127.7250
2015-02-17 14:33:00+00:00           127.8010
2015-02-17 14:34:00+00:00           127.5450
2015-02-17 14:35:00+00:00           127.6300
...
2016-02-17 20:56:00+00:00            98.0900
2016-02-17 20:57:00+00:00            98.0901
2016-02-17 20:58:00+00:00            98.1000
2016-02-17 20:59:00+00:00            98.0500
2016-02-17 21:00:00+00:00            98.1100

I want to select all rows with a certain date, e.g. 2015-02-17.

Whats the best way to achieve that?

2
  • doesn't df.loc['2015-02-17'] work? Commented Oct 10, 2016 at 15:39
  • It does. Thanks for your answer! If you upgrade that to a complete answer, I can mark it. Commented Oct 10, 2016 at 15:41

1 Answer 1

22

DatetimeIndex supports partial datetime strings for label based indexing:

In [18]:
df.loc['2015-02-17']

Out[18]:
                            A
2015-02-17 14:31:00  127.2801
2015-02-17 14:32:00  127.7250
2015-02-17 14:33:00  127.8010
2015-02-17 14:34:00  127.5450
2015-02-17 14:35:00  127.6300
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, is it possible to retain the original df as a DataFrame instead of Series datatype?

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.