I have a dataframe df like
X Y
110 0
110 0
110 1
111 1
111 0
112 1
113 1
114 0
When I filter the datsframe to make operation like len and sum everything works correctly, like here
new = df.x.isin([110,111])
df[new]
len(df[new].y) = 5
sum(df[new].y) = 2
However when I invoke the isin function inside a loop it doesn't work correctly.
I have second dataframe df0 like
col1 . col2
a 110,111
b 113
c 114,1114
d 267,118
e 956
and I want to iterate over df0 and do operation len and sum invoking group gr of element of df.x from df0.col2 like I do in this loop
for i in df0.index:
gr = df0.get_value(i, 'col2')
new = df.x.isin([gr])
df_size = len(df[new].y)
df_sum = sum(df[new].y)
the issue is that in the group gr=110,111 the element 111 is ignored
so the df_size = 3 and df_sum = 1 when instead they should be 5 and 2