タスク重複時間を削除

import io
import pandas as pd

data = """\
task,start,end
A,6:00,8:30
B,6:30,8:00
C,5:30,7:00
D,7:30,9:00
E,10:00,10:30
F,5:00,11:00
"""

df0 = pd.read_csv(io.StringIO(data), index_col=0)

# 時間に変換
df0["start"] = pd.to_timedelta(df0["start"] + ":00")
df0["end"] = pd.to_timedelta(df0["end"] + ":00")

df0

# 全時刻取得・重複消去・ソート
sr0 = pd.Series(df0.stack().unique()).sort_values().reset_index(drop=True)
sr0

# 時間間隔で区切る
df1 = pd.DataFrame({"start": sr0, "end": sr0.shift(-1)}).dropna()
df2 = df0.reset_index().merge(df1.reset_index(), how="cross")

# 条件外は欠損
df2["task"] = df2["task"].where(
    (df2["start_x"] <= df2["start_y"]) & (df2["end_x"] >= df2["end_y"])
)

# 欠損の行を削除
df2.dropna(subset="task", inplace=True)

# 並び替え
df3 = df2.pivot(index="index", columns="task", values="task")

# 1列目のみ取得
df1["work"] = df3.apply(lambda x: pd.Series(x.dropna().values), axis=1).iloc[:, 0]
df1

# 作業時間計算
df1["time"] = df1["end"] - df1["start"]

# 作業時間集計
result = df1.groupby(by="work")["time"].sum().reindex(df0.index, fill_value=pd.Timedelta(0))

# 結果
result