pandas 类型错误:“float”类型的参数不可迭代-Tensorflow wide_n_deep_tutorial

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39643505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 02:04:33  来源:igfitidea点击:

TypeError: argument of type 'float' is not iterable-Tensorflow wide_n_deep_tutorial

pythonpandastensorflow

提问by Vasanti

I am facing an issue while running the wide_n_deep_tutorial program of TensorFlow https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/wide_n_deep_tutorial.pyon my personal data set with variation is the parameters. I am loading my data from S3.

在我的个人数据集上运行 TensorFlow https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/learn/wide_n_deep_tutorial.py的 wide_n_deep_tutorial 程序时遇到一个问题,参数是变化。我正在从 S3 加载我的数据。

My target variable is "impression_flag" which the takes the value of either "TRUE" or "FALSE". Below is the code snippet of the train_and_eval method:

我的目标变量是“impression_flag”,它采用“TRUE”或“FALSE”的值。下面是 train_and_eval 方法的代码片段:

    def train_and_eval():
  """Train and evaluate the model."""
  train_file_name, test_file_name = maybe_download()
  df_train = pd.read_csv(
      tf.gfile.Open(train_file_name),
      names=COLUMNS,
      skipinitialspace=True)
  df_test = pd.read_csv(
      tf.gfile.Open(test_file_name),
      names=COLUMNS,
      skipinitialspace=True,
      skiprows=1)
  df_train[LABEL_COLUMN] = (
      df_train["impression_flag"].apply(lambda x: "TRUE" in x)).astype(int)
  df_test[LABEL_COLUMN] = (
      df_test["impression_flag"].apply(lambda x: "TRUE" in x)).astype(int)

  model_dir = tempfile.mkdtemp() if not FLAGS.model_dir else FLAGS.model_dir
  print("model directory = %s" % model_dir)

  m = build_estimator(model_dir)
  m.fit(input_fn=lambda: input_fn(df_train), steps=FLAGS.train_steps)
  results = m.evaluate(input_fn=lambda: input_fn(df_test), steps=1)
  for key in sorted(results):
    print("%s: %s" % (key, results[key]))

While running the code, an error "Type Error: argument of type 'float' is not iterable" is displayed. The following is the screenshot of the error. enter image description here

运行代码时,显示错误“类型错误:'float' 类型的参数不可迭代”。以下是错误截图。 在此处输入图片说明

Any help would be appreciated!

任何帮助,将不胜感激!

回答by Microos

I got the same problem, it turns out to be caused by the NANin the first line. Please checks this answer: https://stackoverflow.com/a/40223208/5318060

我遇到了同样的问题,结果是由NAN第一行中的引起的。请检查这个答案:https: //stackoverflow.com/a/40223208/5318060