The problem occurs after the first line, a is no longer a DataFrame:
a = [a.ix[i] for i in a.index if sorted1[i]<sorted2[i]] b = [a.ix[i] for i in a.index if sorted1[i]>=sorted2[i]]
This is a list, and therefore does not have an index attribute (hence, errors).
One python trick is to do this on a single line (define them at the same time), i.e.:
a, b = [a.ix[i] for ...], [a.ix[i] for ...]
perhaps the best option is to use a different variable name here (e.g. df).
As you say, there are better ways to do this in pandas, the use of a mask is obvious:
msk = sorted1 < sorted2 seed1 = df[msk].mean() seed2 = df[~msk].mean()
source share