老师,怎么将DataFrame从String类型转成Int类型?
来源:6-5 -DataFrame基本API操作
BaconNUDT
2017-07-21
老师,我读取了一个csv文件
var data = spark.read.option("header", "true").format("csv").load("D:\\train.csv")
但是读进来以后数据是String类型的,怎么将数据变成Int类型
printSchema是这样的
root |-- label: string (nullable = true) |-- pixel0: string (nullable = true) |-- pixel1: string (nullable = true) |-- pixel2: string (nullable = true) |-- pixel3: string (nullable = true) |-- pixel4: string (nullable = true) |-- pixel5: string (nullable = true) |-- pixel6: string (nullable = true) |-- pixel7: string (nullable = true) |-- pixel8: string (nullable = true) |-- pixel9: string (nullable = true) |-- pixel10: string (nullable = true) |-- pixel11: string (nullable = true) |-- pixel12: string (nullable = true) |-- pixel13: string (nullable = true) |-- pixel14: string (nullable = true) |-- pixel15: string (nullable = true) |-- pixel16: string (nullable = true) |-- pixel17: string (nullable = true) |-- pixel18: string (nullable = true) |-- pixel19: string (nullable = true) |-- pixel20: string (nullable = true) |-- pixel21: string (nullable = true) |-- pixel22: string (nullable = true) |-- pixel23: string (nullable = true) |-- pixel24: string (nullable = true) |-- pixel25: string (nullable = true) |-- pixel26: string (nullable = true) |-- pixel27: string (nullable = true) |-- pixel28: string (nullable = true) |-- pixel29: string (nullable = true) |-- pixel30: string (nullable = true)
但是数据应该可以是Int类型
写回答
1回答
-
csv格式有个参数可以指定schema,参考官方文档的使用
012017-07-21
相似问题