-2

enter image description hereI have a dataframe with a column 'date' (YYYY-MM-DD HH:MM:SS) and datetime64 type.

I want to drop/eliminate rows by selecting ranges of dates. How can I do this on python/pandas?

Thank you so much in advance

  • https://stackoverflow.com/questions/22898824/filtering-pandas-dataframes-on-dates – blacksite May 01 '20 at 19:21
  • 1
    Does this answer your question? [Filtering Pandas DataFrames on dates](https://stackoverflow.com/questions/22898824/filtering-pandas-dataframes-on-dates) – blacksite May 01 '20 at 19:21
  • If your dates are unique, you should make it your index. However, I think the easiest way would be to use boolean slicing. `df[~df.date.between(date1, date2)]` – piRSquared May 01 '20 at 19:27
  • Hello piRSquared, how do you input date1 and date2, as timestamps? – Alejandro R. May 01 '20 at 19:54

1 Answers1

0

(I cannot post comments, thus I dare to put an answer) The following questions also refer to deleting or filtering a data frame based on the value of a given column:

Delete rows from a pandas DataFrame based on a conditional expression involving len(string) giving KeyError

Deleting DataFrame row in Pandas based on column value

Basically, you can pass a boolean array to the index operator [ ] of the data frame, this returns the filtered data frame. Here the pandas v1.0.1 (!) documentation of how to index data frames. Also this question is helpful.

braulio
  • 543
  • 2
  • 13