« first day (1 day earlier)      last day (21 days later) » 

18:24
ranges = df2.assign(
   Range=list(map(lambda row:
         list(range(row[0], row[1], 5)),
         df2[["From", "To"]].to_numpy()))
).explode("Range")

matches = (
   df1.merge(
      ranges,
      left_on=["ID", "From"],
      right_on=["ID", "Range"],
      how="left")
)

RM_missing = matches.groupby(["ID", (matches["RM_x"] != matches["RM_x"].shift()).cumsum()])
Q_missing  = matches.groupby(["ID", (matches["Q_x"] != matches["Q_x"].shift()).cumsum()])

matches = pd.concat(
   [
      matches,
Another improved version, should be able to identify the ranges from matches after that.

« first day (1 day earlier)      last day (21 days later) »