I have a dataset with a column which contains dates (e.g. 09/17/20) as object. I want to filter all my rows based on the current month.
import pandas as pd
import datetime as dt
from datetime import datetime
df = pd.read_csv("dataset.csv", dtype="unicode")
now = datetime.now()
df['month_start'] = pd.to_datetime(df['month_start'], format = "%Y-%d-%m")
mask = df['month_start'].dt.strftime("%Y-%m") == datetime.today().strftime("%Y-%m")
include = df[mask]
df.to_csv("dates.csv")
print(datetime.today().strftime("%Y-%m"))
My attempt doesn't filter the dates at all as I want rows with the current month only.