MMM
MMM

Reputation: 972

pandas datetimeindex: get dates in this index that are <= given date

How can one get the list of dates in a datetimeindex that are less or equal to a given date?

What kind of slicing to do?

I have tried to [ index < date ] without success,

Upvotes: 1

Views: 407

Answers (1)

Paul H
Paul H

Reputation: 68146

If it's a series and the index is sorted (it should be) just do:

mySeries[:myDateString]

This is very clearly demnostrated in the documentation: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#datetimeindex-partial-string-indexing

If the index isn't sorted, just use logical indexing:

mySeries[mySeries.index < myTimeStamp]

Upvotes: 2

Related Questions