0
$\begingroup$

Let’s say each element in my population has several attributes. Let’s call then A, B, C, D, E, F.

Let’s say, for simplicity, each attribute has 10 values (but could be any number between 2 and 30). Now I want to get a sample such that the distribution is the same across all features. So for example if the whole population has about 15% of people in feature A with value 1, my sample should be the same.

What should be the way for me to select a size for the sample and choose a sample that has the desired properties?

$\endgroup$
2
  • $\begingroup$ Do you assume that attribute distributions are normal or not ? $\endgroup$
    – etiennedm
    Aug 4 '20 at 15:46
  • $\begingroup$ No, they will not be $\endgroup$
    – user
    Aug 4 '20 at 16:03
0
$\begingroup$

If I understand correctly, you want a sample with along each feature the value below which a given percentage of observations in your population falls. If so, you might want to try something like this using np.percentile:

import numpy as np
import pandas as pd

data = [ np.random.randint(1,10,6) for i in range(20) ] # fake data
df = pd.DataFrame(data=data, columns=['A', 'B', 'C', 'D', 'E', 'F']) # fake dataframe

# 15 being your desired percentage
balanced_sample = [ np.percentile(df[col], 15) for col in df.columns ]
$\endgroup$
2
  • $\begingroup$ Maybe I don’t understand, but this won’t do what I want. I want the sample to have the same percentage for every column and every value of each column at the same time $\endgroup$
    – user
    Aug 4 '20 at 17:58
  • $\begingroup$ By sample, you mean one sample from the population right ? (Maybe this is what I got wrong...) If so, you want to create a sample that has the same percentage for every columns (my example does that) and with the same value for every column as well ? (my example does not) $\endgroup$
    – etiennedm
    Aug 5 '20 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.