Q:

randomly sample rows of a dataframe until the desired sum of a column is reached

I have a dataframe like this:
ID  key   acres
1   156   10
2   157   60
3   158   50
4   159   1
5   160   9
6   161   110

and I want to randomly select rows until the sum of the selected acres from each sampled row reaches 150, or is as close to 150 as possible. I want to store the 'ID' of all the rows that are selected.
I am currently trying to do this:
acres = 0
obid = []
while acres <= 150:
     rows = random.sample(df.index, 1)
     sample= df.ix[rows]
     acres = acres + sample['acres']
     obid.append(sample['ID'])
     df= df.drop(rows)

but there are a couple problems with this approach.  First, it is possible that the same rows are sampled twice since I am dropping the samples within the loop, and not actually changing the original df.  Second, I get this error returned:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

This leads me to believe there is a better approach entirely.

A:

Let's try something like this:

sample pulls a sample row from the dataframe, argument frac=1 states get 100% of
the rows. This basically shuffles the dataframe.
Use iterrrows to iterate through the shuffled dataframe.

Code:
acres = 0
obid = []
for i in df.sample(frac=1).iterrows():
    if (acres + i[1]['acres']) <= 150:
        acres += i[1]['acres']
        obid.append(i[1]['ID'])

print(obid) 

Output:
[5, 6, 4, 1]

Let's look at the original dataframe with results
 print(df[df['ID'].isin(obid)])

Output:
   ID  key  acres
0   1  156     10
3   4  159      1
4   5  160      9
5   6  161    110

