import pandas as pd # 1. Read the CSV file df = pd.read_csv("sales.csv") # 2. Parse dates (DD/MM/YYYY), coercing unparseable values to NaT initial_row_count = len(df) df["parsed_date"] = pd.to_datetime(df["date"], format="%d/%m/%Y", errors="coerce") # Count and drop invalid date rows invalid_rows = df["parsed_date"].isna() skipped_count = invalid_rows.sum() df = df.dropna(subset=["parsed_date"]).copy()
Read sales.csv with pandas. Columns: date (DD/MM/YYYY), product, quantity, unit_price. Work out total revenue for each month, find the 5 products that brought in the most revenue, and write the results to monthly_summary.csv. Skip rows whose date can't be parsed and print how many rows were skipped.
