import pandas as pd
df = pd.DataFrame({
"ID": [ 1, 1, 1, 1, 2, 2],
"Assay": [ 3, 3, 4, 4, 5, 6],
"From": [ 7, 8, 9,10,11,12],
"To": [13,14,15,16,17,18]
})
result = df.groupby(["ID", "Assay"]).agg({"From":['first'], "To":['last']})
print(result)
# From To
# first last
#ID Assay
#1 3 7 14
# 4 9 16
#2 5 11 17
# 6 12 18