python - Pandas Data Frame filtering based off a column condition -


i trying remove rows data frame condition met in 1 column.

lets data frame this:

index  'value 1'   'grade' 1         10         2170a 2         15         2170b 3         10         ncr2170b 4         20         ncr2170a 5         30         ncr2170b 

i want output after filtering this

    index  'value 1'   'grade' 2         15         2170b 3         10         ncr2170b 5         30         ncr2170b 

i have tried many different variations of using list comprehension, looping through each row , evaluating. can make work when use along lines of:

data_filtered = data[data['grade'] == '2170b'] 

but misses entries ncr2170b.

whenever try like:

data_filtered = data['2170b' in data['grade']] 

i key error: 'true'.

i feel missing obvious here.

i have tried using np.where outputs empty array.

you can use str.contains check if string column contains sub string:

df[df.grade.str.contains('2170b')]  #index  value 1    grade #1  2        15    2170b #2  3        10 ncr2170b #4  5        30 ncr2170b 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -