How to Filter DataFrame Rows Based on the Date in Pandas?
Filtering a DataFrame rows by date selects all rows which satisfy specified date constraints, based on a column containing date data. For instance, selecting all rows between March 13, 2020, and December 31, 2020, would return all rows with date values in that range.
Use DataFrame.loc() with the indexing syntax [condition] to select only the rows from DataFrame which satisfy condition.Define condition to check if the date column in DataFrame is within the constraints.It will create a boolean array for all the rows. Only rows having true value will be printed.
Refer below examples. Download the Dataframe from here.
- Convert the data column into date format supported by python
- Filter the rows on the basis of date
- Access rows using .loc() function and store them in dataframe.
All the movies between date 13-Mar-2020 and 31-Dec-2020 will be printed.
The above output prints all the movies added on Netflix in the year 2019.