title: TypeError: argument of type 'float' is not iterable
body: <p>I am new to python and TensorFlow. I recently started understanding and executing TensorFlow examples, and came across this one: <a href="https://www.tensorflow.org/versions/r0.10/tutorials/wide_and_deep/index.html" rel="nofollow noreferrer">https://www.tensorflow.org/versions/r0.10/tutorials/wide_and_deep/index.html</a></p>
  <p>I got the error, <strong>TypeError: argument of type 'float' is not iterable</strong>, and I believe that the problem is with the following line of code:</p>
  <pre><code>df_train[LABEL_COLUMN] = (df_train['income_bracket'].apply(lambda x: '&gt;50K' in x)).astype(int) 
  </code></pre>
  <p>(income_bracket is the label column of the census dataset, with '&gt;50K' being one of the possible label values, and the other label is '=&lt;50K'. The dataset is read into df_train. The explanation provided in the documentation for the reason to do the above is, &quot;Since the task is a binary classification problem, we'll construct a label column named &quot;label&quot; whose value is 1 if the income is over 50K, and 0 otherwise.&quot;)</p>
  <p>If anyone could explain me what is exactly happening and how should I fix it, that'll be great. I tried using Python2.7 and Python3.4, and I don't think that the problem is with the version of the language. Also, if anyone is aware of great tutorials for someone who is new to TensorFlow and pandas, please share the links.</p>
  <p>Complete program:</p>
  <pre><code>import pandas as pd
  import urllib
  import tempfile
  import tensorflow as tf
  
  gender = tf.contrib.layers.sparse_column_with_keys(column_name=&quot;gender&quot;, keys=[&quot;female&quot;, &quot;male&quot;])
  race = tf.contrib.layers.sparse_column_with_keys(column_name=&quot;race&quot;, keys=[&quot;Amer-Indian-Eskimo&quot;, &quot;Asian-Pac-Islander&quot;, &quot;Black&quot;, &quot;Other&quot;, &quot;White&quot;])
  education = tf.contrib.layers.sparse_column_with_hash_bucket(&quot;education&quot;, hash_bucket_size=1000)
  marital_status = tf.contrib.layers.sparse_column_with_hash_bucket(&quot;marital_status&quot;, hash_bucket_size=100)
  relationship = tf.contrib.layers.sparse_column_with_hash_bucket(&quot;relationship&quot;, hash_bucket_size=100)
  workclass = tf.contrib.layers.sparse_column_with_hash_bucket(&quot;workclass&quot;, hash_bucket_size=100)
  occupation = tf.contrib.layers.sparse_column_with_hash_bucket(&quot;occupation&quot;, hash_bucket_size=1000)
  native_country = tf.contrib.layers.sparse_column_with_hash_bucket(&quot;native_country&quot;, hash_bucket_size=1000)
  
  
  age = tf.contrib.layers.real_valued_column(&quot;age&quot;)
  age_buckets = tf.contrib.layers.bucketized_column(age, boundaries=[18, 25, 30, 35, 40, 45, 50, 55, 60, 65])
  education_num = tf.contrib.layers.real_valued_column(&quot;education_num&quot;)
  capital_gain = tf.contrib.layers.real_valued_column(&quot;capital_gain&quot;)
  capital_loss = tf.contrib.layers.real_valued_column(&quot;capital_loss&quot;)
  hours_per_week = tf.contrib.layers.real_valued_column(&quot;hours_per_week&quot;)
  
  wide_columns = [gender, native_country, education, occupation, workclass, marital_status, relationship, age_buckets, tf.contrib.layers.crossed_column([education, occupation], hash_bucket_size=int(1e4)), tf.contrib.layers.crossed_column([native_country, occupation], hash_bucket_size=int(1e4)), tf.contrib.layers.crossed_column([age_buckets, race, occupation], hash_bucket_size=int(1e6))]
  
  deep_columns = [
    tf.contrib.layers.embedding_column(workclass, dimension=8),
    tf.contrib.layers.embedding_column(education, dimension=8),
    tf.contrib.layers.embedding_column(marital_status, dimension=8),
    tf.contrib.layers.embedding_column(gender, dimension=8),
    tf.contrib.layers.embedding_column(relationship, dimension=8),
    tf.contrib.layers.embedding_column(race, dimension=8),
    tf.contrib.layers.embedding_column(native_country, dimension=8),
    tf.contrib.layers.embedding_column(occupation, dimension=8),
    age, education_num, capital_gain, capital_loss, hours_per_week]
  
  model_dir = tempfile.mkdtemp()
  m = tf.contrib.learn.DNNLinearCombinedClassifier(
      model_dir=model_dir,
      linear_feature_columns=wide_columns,
      dnn_feature_columns=deep_columns,
      dnn_hidden_units=[100, 50])
  
  
  COLUMNS = [&quot;age&quot;, &quot;workclass&quot;, &quot;fnlwgt&quot;, &quot;education&quot;, &quot;education_num&quot;,
    &quot;marital_status&quot;, &quot;occupation&quot;, &quot;relationship&quot;, &quot;race&quot;, &quot;gender&quot;,
    &quot;capital_gain&quot;, &quot;capital_loss&quot;, &quot;hours_per_week&quot;, &quot;native_country&quot;, &quot;income_bracket&quot;]
  LABEL_COLUMN = 'label'
  CATEGORICAL_COLUMNS = [&quot;workclass&quot;, &quot;education&quot;, &quot;marital_status&quot;, &quot;occupation&quot;, &quot;relationship&quot;, &quot;race&quot;, &quot;gender&quot;, &quot;native_country&quot;]
  CONTINUOUS_COLUMNS = [&quot;age&quot;, &quot;education_num&quot;, &quot;capital_gain&quot;, &quot;capital_loss&quot;, &quot;hours_per_week&quot;]
  
  
  train_file = tempfile.NamedTemporaryFile()
  test_file = tempfile.NamedTemporaryFile()
  urllib.urlretrieve(&quot;https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data&quot;, train_file.name)
  urllib.urlretrieve(&quot;https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.test&quot;, test_file.name)
  
  
  df_train = pd.read_csv(train_file, names=COLUMNS, skipinitialspace=True)
  df_test = pd.read_csv(test_file, names=COLUMNS, skipinitialspace=True, skiprows=1)
  df_train[LABEL_COLUMN] = (df_train['income_bracket'].apply(lambda x: '&gt;50K' in x)).astype(int)
  df_test[LABEL_COLUMN] = (df_test['income_bracket'].apply(lambda x: '&gt;50K' in x)).astype(int)
  
  
  def input_fn(df):
  
    continuous_cols = {k: tf.constant(df[k].values)
                       for k in CONTINUOUS_COLUMNS}
  
    categorical_cols = {k: tf.SparseTensor(
        indices=[[i, 0] for i in range(df[k].size)],
        values=df[k].values,
        shape=[df[k].size, 1])
                        for k in CATEGORICAL_COLUMNS}
  
    feature_cols = dict(continuous_cols.items() + categorical_cols.items())
    label = tf.constant(df[LABEL_COLUMN].values)
    return feature_cols, label
  
  
  def train_input_fn():
      return input_fn(df_train)
  
  
  def eval_input_fn():
      return input_fn(df_test)
  
  m.fit(input_fn=train_input_fn, steps=200)
  results = m.evaluate(input_fn=eval_input_fn, steps=1)
  for key in sorted(results):
      print(&quot;%s: %s&quot; % (key, results[key]))
  </code></pre>
  <p>Thank you</p>
  <p>PS: Full stack trace for the error</p>
  <pre><code>Traceback (most recent call last):
    
  File &quot;/home/jaspreet/PycharmProjects/TicTacTensorFlow/census.py&quot;, line 73, in &lt;module&gt;
      df_train[LABEL_COLUMN] = (df_train['income_bracket'].apply(lambda x: '&gt;50K' in x)).astype(int)
    
  File &quot;/usr/lib/python2.7/dist-packages/pandas/core/series.py&quot;, line 2023, in apply
      mapped = lib.map_infer(values, f, convert=convert_dtype)
   
  File &quot;inference.pyx&quot;, line 920, in pandas.lib.map_infer (pandas/lib.c:44780)
    
  File &quot;/home/jaspreet/PycharmProjects/TicTacTensorFlow/census.py&quot;, line 73, in &lt;lambda&gt;
      df_train[LABEL_COLUMN] = (df_train['income_bracket'].apply(lambda x: '&gt;50K' in x)).astype(int)
  
  TypeError: argument of type 'float' is not iterable
  </code></pre>