title: Filter data in Tensorflow
body: <p>I have some column data in TensorFlow and I'd like to filter on one of the columns, like so:</p>
  
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  
  import tensorflow.compat.v2 as tf
  import tensorflow.compat.v1 as tfv1
  tfv1.enable_v2_behavior()
  
  csv_file = tf.keras.utils.get_file('heart.csv', 'https://storage.googleapis.com/applied-dl/heart.csv')
  
  df = pd.read_csv(csv_file)
  target = df.pop('target')
  df['thal'] = pd.Categorical(df['thal'])
  df['thal'] = df.thal.cat.codes
  
  # Use interleave() and prefetch() to read many files concurrently.
  #files = tf.data.Dataset.list_files(file_pattern=input_file_pattern, shuffle=True, seed=123456789)
  #dataset = files.interleave(lambda x: tf.data.RecordIODataset(x).prefetch(100), cycle_length=8)
  
  #Pretend I actually had some data files
  dataset = tf.data.Dataset.from_tensor_slices((df.to_dict('list'), target.values))
  
  dataset = dataset.shuffle(1000, seed=123456789)
  dataset = dataset.batch(20)
  #Pretend I did some parsing here
  # dataset = dataset.map(parse_record, num_parallel_calls=20) 
  dataset = dataset.filter(lambda x, label: x['trestbps']&lt;135)
  </code></pre>
  
  <p>But this produces the error message:</p>
  
  <blockquote>
    <p>ValueError: <code>predicate</code> return type must be convertible to a scalar boolean tensor. Was <code>TensorSpec(shape=(None,), dtype=tf.bool, name=None)</code>.</p>
  </blockquote>
  
  <p>What should I do to filter the data?</p>