我有一个很大的DataFrame,由大约550列双精度和两列长整型(ids)组成。550列是从csv读取的,我添加了两个id列。我对数据所做的唯一其他事情是将一些csv数据从字符串更改为双精度("Inf“-> "0”,然后将列转换为双精度),并将NaN的数据替换为0:
df = df.withColumn(col.name + "temp",
regexp_replace(
regexp_replace(df(col.name),"Inf","0")
,"NaN","0").cast(DoubleType))
df = df.drop(col.name).withColumnRenamed(col.name + "temp",col.name)
df = df.withColumn("timeId", monotonically_increasing_id.cast(LongType))
df = df.withColumn("patId", lit(num).cast(LongType))
df = df.na.fill(0)当我进行计数时,我得到以下错误:
IllegalArgumentException: requirement failed: Decimal precision 6 exceeds max precision 5有数十万行,我正在读取来自多个csvs的数据。如何提高小数精度?还有其他可能发生的事情吗?只有当我读入一些csvs时,我才会得到这个错误。他们可能比其他人有更多的小数吗?
发布于 2017-06-01 06:15:55
我认为这个错误是不言而喻的--你需要使用DecimalType而不是DoubleType。
试试这个:
...
.cast(DecimalType(6)))继续阅读:
https://spark.apache.org/docs/2.1.0/api/java/org/apache/spark/sql/types/DecimalType.html
http://spark.apache.org/docs/2.0.2/api/python/_modules/pyspark/sql/types.html
https://stackoverflow.com/questions/44294972
复制相似问题