Pandas not inside and between

paid version '0.14.0'

What I need to do is not in the instructions for the column in the data frame.

for the isin operator, I use the following to filter the codes I need:

h1 = df1[df1['nat_actn_2_3'].isin(['100','101','102','103','104'])]

I want to do not in or not equal (not sure which one is used for python) for another column.

So, I tried the following:

h1 = df1[df1['csc_auth_12'].notin(['N6M','YEM','YEL','YEM'])]

h1 = df1[df1['csc_auth_12'] not in (['N6M','YEM','YEL','YEM'])]

and

h1.query(['N6M','YEM','YEL','YEM'] not in ['csc_auth_12'])

I really want to filter N6M, YEM, YEL and YEM from a dataset.

I am also interested in how to make an operator between.

So, for the next, I had to manually enter all 500 codes. I would like to do something like:

h1 = df1[df1['nat_actn_2_3'].isin['100','102'] and isbetween [500 & 599])]

but this is what I have:

h1 = df1[df1['nat_actn_2_3'].isin(['100','101','102','103','104','107','108','112','115','117','120','122','124','128',
                             '130','132','132','140','141','142','143','145','146','147','148','149','170','171',
                             '172','173','179','190','198','199','501','502','503','504','505','506','507','508',
                             '509','510','511','512','513','514','515','516','517','518','519','520','521','522',
                             '523','524','525','526','527','528','529','530','531','532','533','534','535','536',
                             '537','538','539','540','541','542','543','544','545','546','547','548','549','550',
                             '551','552','553','554','555','556','557','558','559','560','561','562','563','564',
                             '565','566','567','568','569','570','571','572','573','574','575','576','577','578',
                             '579','580','581','582','583','584','585','586','587','588','589','590','591','592',
                             '593','594','595','596','597','598','599','702','721','740','953','955'])]

Any suggestions?

thanks.

+4
source share
1 answer

, ~ :

h1 = df1[~df1['nat_actn_2_3'].isin(['100','101','102','103','104'])]

notin not in, , , , ValueError , in , pandas .

:

h1 = df1[(df1['nat_actn_2_3'].isin['100','102']) | ((df1['nat_acctn_2_3'] > 500) & (df1['nat_actn_2_3'] < 599))]

, , , 100/102 500 599 (, , >= <= ).

& | and or , () -

+5

Source: https://habr.com/ru/post/1610505/