我正在尝试加载 csv
的数据保存在 GCS
中的文件进入 BigQuery
. csv 文件位于 UTF-8
格式,它包含 7 列。我已经在数据方案中指定了这些列(所有字符串和可为空的),并且我已经检查了 csv 文件的内容,这看起来不错。
当我尝试加载数据时,出现以下错误:
Too many errors encountered. (error code: invalid) gs://gvk_test_bucket/sku_category.csv: CSV table references column position 1, but line starting at position:1750384 contains only 1 columns. (error code: invalid)
奇怪的是,该文件只包含 680228 行。
当我查看
allow jagged lines
options 正在生成表,但只有第一列填充了整个逗号分隔的字符串。有人能帮我吗?
示例行
119470,Fashion,Fashion Own,Menswear,Menswear Brands Other,Formal Shirts,Long Sleeve Shirts
最佳答案
对我来说,这是存在换行符和回车符的问题,请尝试替换特殊字符。我已经使用下面的代码替换了字符,它解决了加载部分。
df= df.applymap(lambda x: x.replace("\r"," "))
df= df.applymap(lambda x: x.replace("\n"," "))
我使用了 lambda 函数,因为我不知道在我的情况下哪一列是字符串。如果您确定列,则明智地替换其列。
尝试替换字符,它也适用于您。
关于csv - 从 Google Cloud Storage 加载 csv 文件时出现 BigQuery 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42390005/