janitor.filter_date(df: pandas.core.frame.DataFrame, column_name: Hashable, start_date: Optional[datetime.date] = None, end_date: Optional[datetime.date] = None, years: Optional[List] = None, months: Optional[List] = None, days: Optional[List] = None, column_date_options: Optional[Dict] = None, format: Optional[str] = None) → pandas.core.frame.DataFrame[source]

Filter a date-based column based on certain criteria.

This method does not mutate the original DataFrame.

Dates may be finicky and this function builds on top of the “magic” from the pandas to_datetime function that is able to parse dates well.

Additional options to parse the date type of your column may be found at the official pandas documentation:


Note: This method will cast your column to a Timestamp!

  • df – A pandas dataframe.

  • column_name – The column which to apply the fraction transformation.

  • start_date – The beginning date to use to filter the DataFrame.

  • end_date – The end date to use to filter the DataFrame.

  • years – The years to use to filter the DataFrame.

  • months – The months to use to filter the DataFrame.

  • days – The days to use to filter the DataFrame.

  • column_date_options – ‘Special options to use when parsing the date column in the original DataFrame. The options may be found at the official Pandas documentation.’

  • format – ‘If you’re using a format for start_date or end_date that is not recognized natively by pandas’ to_datetime function, you may supply the format yourself. Python date and time formats may be found at http://strftime.org/.’


A filtered pandas DataFrame.

Note: This only affects the format of the start_date and end_date parameters. If there’s an issue with the format of the DataFrame being parsed, you would pass {‘format’: your_format} to column_date_options.