python pandas filter out rows does not work -


i want filter pandas dataframe 1 column called 'mid', retain rows has field 'mid' within particular range.

my code follow:

df_org dataframe of structure ['uid','mid','cv1','cv2','cv3'], , series_moviesid pandas series contain values want use filter df_org dataframe.

filterout(self, df_org, series_movieid, colname='mid'):     mask=((df_org[colname]).isin(series_movieid))     df_filterout = df_org[mask]     assert set(df_filterout['mid']).issubset(set(series_movieid))     return df_filterout.reset_index().drop(labels='index', axis=1) 

but assert expression not pass, know potential mistake?

hm. code works me. tried dupes in s, df, , both , ran. more details can share?

in [2]: s = pd.series(range(4), index=['a', 'b', 'c', 'd'])  in [3]: df = pd.dataframe({'a': range(10), 'b': range(10, 20)}, index=range(20, 30))  in [4]:  in [4]: print s    0 b    1 c    2 d    3 dtype: int64  in [5]: print df       b 20  0  10 21  1  11 22  2  12 23  3  13 24  4  14 25  5  15 26  6  16 27  7  17 28  8  18 29  9  19  in [6]: def filterout(df_org, series_movieid, colname='mid'):    ...:         mask=((df_org[colname]).isin(series_movieid))    ...:         df_filterout = df_org[mask]    ...:         assert set(df_filterout[colname]).issubset(set(series_movieid))    ...:         return df_filterout.reset_index().drop(labels='index', axis=1)    ...:  in [7]: filterout(df, s, colname='a') out[7]:      b 0  0  10 1  1  11 2  2  12 3  3  13 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -