I have a data set for Group and IDs of the Farmers. I have to select 6 Farmers out of 18 farmers using Stratified Random Sampling where percentage is given for sampling.
Group wise percentage as below
Date Set:
Now, Using Sampling, I have to select 6 farmers, where 6x0.50=3 farmers from Group :"M,SC", 6x0.25=2 farmers from group F,SC and 1 farmer from Group M,ST will be select.
Here is what I have so far:
df
Out[41]:
Group ID
0 M,SC 1
1 M,SC 2
2 M,SC 3
3 M,SC 4
4 M,SC 5
5 F,SC 6
6 F,SC 7
7 F,SC 8
8 F,SC 9
9 M,ST 10
10 M,ST 11
11 M,ST 12
12 M,ST 13
13 M,ST 14
14 F,ST 15
15 F,ST 16
16 F,ST 17
17 F,ST 18
N=6
df.groupby('Group', group_keys=False).apply(lambda x: x.sample(int(np.rint(N*len(x)/len(df))))).sample(frac=1).reset_index(drop=True)
Out[43]:
Group ID
0 M,ST 14
1 M,SC 3
2 M,ST 10
3 M,SC 2
4 F,ST 15
5 F,SC 7
Now, I am stuck on how to apply the given % in the sampling like for M,SC group:50%, F,SC group:25%, M,ST group:20% and F,ST group 5%, the above code proportionally select sample of N=6.


