I have the following data frame:
import pandas as pd
units = [1, 1, 1, 5, 5, 5]
locations = [30, 30, 30, 32, 32, 32]
timestamps = [1, 2, 3, 1, 2, 3]
quantities = [1, 5, 3, 10, 35, 39]
data = {'units': units, 'locations': locations, 'timestamps': timestamps,
'quantities': quantities}
df = pd.DataFrame(data=data)
that looks like this:
🐍 >>> df
units locations timestamps quantities
0 1 30 1 1
1 1 30 2 5
2 1 30 3 3
3 5 32 1 10
4 5 32 2 35
5 5 32 3 39
I need to get a list of data frames from all unique combinations of units and locations, i.e. something that uses df.groupby(['units', 'locations']). The end result should look something like this:
(1, 30)
timestamps quantities
0 1 1
1 2 5
2 3 3
(5, 32)
timestamps quantities
3 1 10
4 2 35
5 3 39
is this possible, please?