'How to merge next rows' start with current rows' end in Python

For example if I have a DataFrame that looks like this

enter image description here

For the same id and Category, I would like to keep only the first start and last end number and eliminate the middle ones. For example, for row 0 and 1, since their id are both A and category are both Cat_1, the start would be 1 and end would be 3. The expected output would look like this:

enter image description here

Feel free to use the following code to explore:

import pandas as pd
data = {'id':  ['A','A','A', 'B', 'B', 'C' , 'D'],
        'start': [1,2,3,4,5,6,7],
        'end': [2,3,4,5,6,7,8],
        'Category':['Cat_1', 'Cat_1', 'Cat_2' , 'Cat_3', 'Cat_3', 'Cat_3', 'Cat_3']
        }

df = pd.DataFrame(data)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source