I have the following framework:
data = {'VehID' : pd.Series([10000,10000,10000,10001,10001,10001,10001]), 'JobNo' : pd.Series([1,2,2,1,2,3,3]), 'Material' : pd.Series([5005,5100,5005,5888,5222,5888,5222])} df = pd.DataFrame(data, columns=['VehID','JobNo','Material'])
It looks like this:
VehID JobNo Material 0 10000 1 5005 1 10000 2 5100 2 10000 2 5005 3 10001 1 5888 4 10001 2 5222 5 10001 3 5888 6 10001 3 5222
I would like to identify materials that occur in sequential jobs for each vehicle. For instance,
VehID Material Jobs 10000 5005 [1,2] 10001 5222 [2,3]
I would like to avoid working with loops. Does anyone have any suggestions for neat solutions for this? Thanks in advance.
source share