Pandas - Python, deleting rows based on Date column
date, datetime, pandas, python
Solution
You can just filter them out:
df[(df['Delivery Date'].dt.year == 1970) | (df['Delivery Date'] >= sixmonthago)]
This returns all rows where the year is 1970 or the date is less than 6 months.
You can use boolean indexing and pass multiple conditions to filter the df, for multiple conditions you need to use the array operators so `|` instead of `or`, and parentheses around the conditions due to operator precedence.
Check the docs for an explanation of boolean indexing
Problem
I'm trying to delete rows of a dataframe based on one date column; `[Delivery Date]` I need to delete rows which are older than 6 months old but not equal to the year '1970'. I've created 2 variables: ``` from datetime import date, timedelta sixmonthago = date.today() - timedelta(188) import time nineteen_seventy = time.strptime('01-01-70', '%d-%m-%y') ``` but I don't know how to delete rows based on these two variables, using the `[Delivery Date]` column. Could anyone provide the correct solution?