Вы можете использовать решение numpy с указанными значениями для диапазона get + -4 и фильтровать по boolean indexing
:
print (df)
Status Height Object
0 Here 100' ABC
1 Maybe here 99' ABC
2 Maybe here 102' ABC
3 Maybe here 99' ABC
4 Here 80' XYZ
5 Maybe here 78' XYZ
#specify values for check ranges
vals = [100, 80]
#remove traling 'and convert to integer
a = df['Height'].str.strip("'").astype(int)
#convert to numpy array and compare, get abs values
arr = np.abs(np.array(vals) - a.values[:, None])
print (arr)
[[ 0 20]
[ 1 19]
[ 2 22]
[ 1 19]
[20 0]
[22 2]]
#xreate boolean mask for match at least one True
mask = np.any((arr > 0) & (arr < 4), axis=1)
print (mask)
[False True True True False True]
#inverting condition by ~
print (df[~mask])
Status Height Object
0 Here 100' ABC
4 Here 80' XYZ
Аналогично:
#invert conditions and check if all values Trues per row
mask = np.all((arr <= 0) | (arr >= 4), axis=1)
print (mask)
[ True False False False True False]
print (df[mask])
Status Height Object
0 Here 100' ABC
4 Here 80' XYZ
EDIT:
Решение аналогично только новой логической цепочке, созданной DataFrame.duplicated
:
#specify values for check ranges
vals = [100, 80]
#remove traling 'and convert to integer
a = df['Height'].str.strip("'").astype(int)
#convert to numpy array and compare, get abs values
arr = np.abs(np.array(vals) - a.values[:, None])
print (arr)
[[ 0 20]
[ 1 19]
[ 2 22]
[ 1 19]
[20 0]
[22 2]]
#create boolean mask for match at least one True
mask1 = np.any((arr > 0) & (arr < 4), axis=1)
print (mask1)
[False True True True False True]
mask2 = df.duplicated(subset=['Object','Store'], keep=False)
print (mask2)
0 True
1 True
2 False
3 False
4 False
5 False
dtype: bool
mask = mask1 & mask2
#inverting condition by ~
print (df[~mask])
Status Height Object Store
0 Here 100' ABC EFG
2 Maybe here 102' ABC JKL
3 Maybe here 99' ABC QRS
4 Here 80' XYZ QRS
5 Maybe here 78' XYZ JKL
#invert conditions and check if all values Trues per row
mask3 = np.all((arr <= 0) | (arr >= 4), axis=1)
print (mask3)
[ True False False False True False]
mask = mask3 | ~mask2
print (df[mask])
Status Height Object Store
0 Here 100' ABC EFG
2 Maybe here 102' ABC JKL
3 Maybe here 99' ABC QRS
4 Here 80' XYZ QRS
5 Maybe here 78' XYZ JKL