I am trying to figure out how to use pandas groupby.
My dataframe looks like this
index ID Code Quantity
0 400 ZU 5000
1 400 ZO 12
2 401 ZU 9000
3 401 ZO 15
4 402 ZU 1000
5 403 ZO 15
I'd like to groupby ID and Code and create an extra column which devides the Quantity of ZU by the quantity of ZO, but only if the groupby has an entry for both. If one is missing the data can be dropped.
I know I can groupby multiple columns like:
data.groupby(['ID', 'Code'])
But I've no idea how to proceed from there, since I don't need the .sum()
or the .mean()
valuze.
The expected output could be something like this:
index ID value
0 400 416.17
1 401 600