我在试着从运输部读取机上数据。它存储在CSV中,并继续获取java.lang.NumberFormatException: null
我尝试过将nanValue设置为空字符串,因为它的默认值是NaN,但这没有起作用。在
我目前的代码是:spark = SparkSession.builder \
.master('local') \
.appName('Flight Delay') \
.getOrCreate()
schema = StructType([
StructField('Year', IntegerType(), nullable=True),
StructField('Month', IntegerType(), nullable=True),
StructField('Day', IntegerType(), nullable=True),
StructField('Dow', IntegerType(), nullable=True),
StructField('CarrierId', StringType(), nullable=True),
StructField('Carrier', StringType(), nullable=True),
StructField('TailNum', StringType(), nullable=True),
StructField('Origin', StringType(), nullable=True),
StructField('Dest', StringType(), nullable=True),
StructField('CRSDepTime', IntegerType(), nullable=True),
StructField('DepTime', IntegerType(), nullable=True),
StructField('DepDelay', DoubleType(), nullable=True),
StructField('TaxiOut', DoubleType(), nullable=True),
StructField('TaxiIn', DoubleType(), nullable=True),
StructField('CRSArrTime', IntegerType(), nullable=True),
StructField('ArrTime', IntegerType(), nullable=True),
StructField('ArrDelay', DoubleType(), nullable=True),
StructField('Cancelled', DoubleType(), nullable=True),
StructField('CancellationCode', StringType(), nullable=True),
StructField('Diverted', DoubleType(), nullable=True),
StructField('CRSElapsedTime', DoubleType(), nullable=True),
StructField('ActualElapsedTime', DoubleType(), nullable=True),
StructField('AirTime', DoubleType(), nullable=True),
StructField('Distance', DoubleType(), nullable=True),
StructField('CarrierDelay', DoubleType(), nullable=True),
StructField('WeatherDelay', DoubleType(), nullable=True),
StructField('NASDelay', DoubleType(), nullable=True),
StructField('SecurityDelay', DoubleType(), nullable=True),
StructField('LateAircraftDelay', DoubleType(), nullable=True)
])
flts = spark.read \
.format('com.databricks.spark.csv') \
.csv('/home/william/Projects/flight-delay/data/201601.csv',
schema=schema, nanValue='', header='true')
最后一行是它中断并引发java.lang.NumberFormatException: null
似乎有些数值列是空字符串,而有些列只是空字符串。有人能帮我吗?在