convert Int64Index to Int

The answer to your specific question is that index1 is an Int64Index (basically a list), even if it has one element. To get that one element, you can use index1[0].

But there are better ways of accomplishing your goal. If you want to remove all of the rows in the "bad" groups, you can use filter:

hdf = hdf.groupby('group_id').filter(lambda group: group['criteria1'].max() != 0)

If you only want to remove certain rows within matching groups, you can write a function and then use apply:

def filter_group(group):
    if group['criteria1'].max() != 0:
        return group
    else:
        return group.loc[other criteria here]

hdf = hdf.groupby('group_id').apply(filter_group)

(If you really like your current way of doing things, you should know that loc will accept an index, not just an integer, so you could also do hdf.loc[group.index, 'remove_row'] = 1).


call tolist() on Int64Index object. Then the list can be iterated as int values.

Tags:

Pandas