Python Pandas Dataframe sampling
My best guess: 'protect' one random row from each id (create separate dataframe with those rows), then delete from original dataframe until satisfied (including the fact that the classes in the 'protected' dataframe will line up flush with what remains) and concatenate the two dataframes?
I am looking for an elegant way to sample a dataset in a specific way. I found a few solutions, but I was wondering if any of you know a better way.
Here is the task I am looking at:
I want to balance my dataset, so that I have the same amount of instances for class 0 as for class 1, so in the example below we have 5 instances of class 1 and 11 instances of class 0:

id | class
------ | ------ 
1 | 1
1 | 0
1 | 0
1 | 0
1 | 0
2 | 1
2 | 1
2 | 0
2 | 0 
2 | 0
3 | 1
3 | 1
3 | 0
3 | 0
3 | 0
3 | 0

Sofar I have just deleted randomly 6 instances of class 0, but I would like to prevent that all instances of one id could get deleted. I tried doing a stratified "split", with sklearn, but it does not work, because not every id contains more than 1 item. The desired output should look similar to this:

id | class
------ | ------ 
1 | 1
1 | 0
2 | 1
2 | 1
2 | 0
2 | 0 
3 | 1
3 | 1
3 | 0
3 | 0

Any good ideas?