tf.decode_csv() error: “Unquoted fields cannot have quotes/CRLFs inside”

今天利用模型预测表中的数据写到另外一个表中爆这个错误,找了一些资料没找到原因,后来查看函数的本身用法,有个参数是use_quote_delim 参数,看原始代码的解释为:

se_quote_delim: An optional `bool`. Defaults to `True`.
      If false, treats double quotation marks as regular
      characters inside of the string fields (ignoring RFC 4180, Section 2,
      Bullet 5).

设置为True,会把双引号当成引用,在使用tf.decode_csv读取文件的时候如果某一行有双引号会报错,如果设置为False会把双引号当做为一个普通的字符串变量,在这里读取不会报错,下面可以尝试下:

badcase.txt:

827412029,阿娇自称食量不如阿Sa 惨遭谢霆锋狠怼"去你的"
454095720,蒋欣变特工性感诱惑 郑恺当众宣布"出柜" 161112
830976059,郭德纲调戏喜剧人,开扒"不能播的秘密"
321042110,容祖儿比基尼上阵只为胜利 陈妍希最爱孙杨"英雄救美" 150713
 

code:

import tensorflow as tf
filenames = tf.train.string_input_producer(["badcase.txt"], num_epochs=2)

reader = tf.TextLineReader()

_, line = reader.read(filenames)

col1, col2 = tf.decode_csv(line,use_quote_delim=False,
                           record_defaults=[tf.constant([],dtype=tf.string),
                                            tf.constant([],dtype=tf.string)])
sess=tf.Session()
sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
tf.train.start_queue_runners(sess)

for i in range(10):
    print(sess.run([col1, col2]))

在代码中你设置为True,会爆标题的错误。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值