1
我有這樣的csv文件上稱輸入:星火變換RDD
time,col1,col2,col3
0,5,8,9
1,6,65,3
2,5,8,465,4
3,85,45,8
數列的未知 ,我希望在格式導致RDD:
(constant,column,time,value)
這意味着: ((CAR 1 ,col1,0,5),(car1,col2,1,8)..)
我有RDD的時間,行和標題
class SimpleCSVHeader(header:Array[String]) extends Serializable {
val index = header.zipWithIndex.toMap
def apply(array:Array[String], key:String):String = array(index(key))
}
val constant = "car1"
val csv = sc.textFile("C:\\file.csv")
val data = csv.map(line => line.split(",").map(elem => elem.trim))
val header = new SimpleCSVHeader(data.take(1)(0)) // we build our header with the first line
val rows = data.filter(line => header(line,"time") != "time") // filter the header out
val time = rows.map(row => header(row,"time"))
,但我不知道如何從