data = [{"time": "2022-04-01T12:09:46.929+0800", "op": "query", "cost": 100, "db_name": "dbname"}]
df = pd.DataFrame(data=df_data, columns=["time", "op", "cost", "db_name"])
df["time"] = pd.to_datetime(df["time"])
df.set_index("time", inplace=True)
df["cost"] = df["cost"].astype(int)_
_pd.set_option("display.max_rows", None)
time_group = df["2022-04-01 00:00:00":"2022-04-01 23:59:05"].groupby("db_name").resample("60Min")_
_print(time_group.apply(lambda x: pd.Series({ "avg_cost": x["cost"].mean(), "max": x["cost"].max(), "max_arg": x["cost"].idxmax() if not x["cost"].empty else None, "min": x["cost"].min(), "min_arg": x["cost"].idxmin() if not x["cost"].empty else None, "median": x["cost"].median(), "count": x["cost"].count() })))