title: Spark: Read CSV file with headers
body: <p>I have a CSV file with 90 columns and around 28000 rows.</p>
  
  <p>I want to load it and split it in train (75%) and test (25%). I used the following code:</p>
  
  <p>Code:</p>
  
  <pre><code>val data = sc.textFile(datadir + "/dados_frontwave_corte_pedra_ferramenta.csv")
          .map(line =&gt; line.split(","))
              .filter(line =&gt; line.length&gt;1)
          .collect();
  
  // Building the model
  val numIterations = 20;
  val model = LinearRegressionWithSGD.train(data, numIterations);
  </code></pre>
  
  <p>I get the following error on the "data":</p>
  
  <pre><code>type mismatch; found : Array[Array[String]] required: org.apache.spark.rdd.RDD[org.apache.spark.mllib.regression.LabeledPoint]
  </code></pre>
  
  <p>What is the problem? I search it on the internet and I couldn't find any clear answer.</p>
  
  <p>I found this <a href="https://altiscale.zendesk.com/hc/en-us/articles/202627136-Spark-Shell-Examples" rel="nofollow">Spark Example</a> and change my code as follow:</p>
  
  <pre><code>val data = sc.textFile(datadir + "/dados_frontwave_corte_pedra_ferramenta.csv")
  val parsedData = data.map {line =&gt;
      val parts = line.split(",")
      LabeledPoint(parts(0).toDouble, Vectors.dense(parts(1).split(",").map(x =&gt; x.toDouble).toArray))
      };
  </code></pre>
  
  <p>The error has gone but when I run the code the following error is produced:</p>
  
  <pre><code>15/04/15 16:53:52 ERROR Executor: Exception in task 1.0 in stage 0.0 (TID 1)
  java.lang.NumberFormatException: For input string ""12316""
  at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
  at sun.misc.FloatingDecimal.parseDouble(Unknown Source)
  at scala.collection.immutable.StringLinke$class.toDouble(StringOps.scala:31)
  ....
  </code></pre>
  
  <p>Sample of input file:</p>
  
  <pre><code>"","Ferramenta","Pedra","ensaio","Nrasgo","Vcorte","Vrotacional","PCorte","Tempo","Fh","Fr","Energia","Caudal","Vib_disco","Vib_maquina","xx","yy","zz","Fonte","id","rocha_classe","rocha_tipo","Resistência_mecânica_à_compressão","Res._mec._à_compr._após_teste_de_gelividade","Resistência_mecânica_à_flexão","Massa_volúmica_aparente","Absorção_de_água_à_P._At.N.","Porosidade_aberta","Coef._de_dilatação_linear_térmica_val._máx","Resistência_ao_desgaste","Resistência_ao_choque_altura_minima_de_queda","Resistência_ao_gelo","Al2O3","CaO","H2O.","K2O","MgO","MnO","Na2O","P2O5","SiO2","TiO2","microclina","plagioclase","quartzo","page_id","rocha_nome_2","P.R._.L.O.I..","plagioclase_.oligoclase.albite.","feldspato_potássico_.microclina.","feldspato_potássico_.essencialmente_microclina.","biotite","rocha_nome_3","oligoclase","plagioclase_.andesina.","horneblenda","feldspato_potássico","nefelina","aegirina_e_aegirina.augite","esfena","piroxena","olivina","horneblenda_verde","plagioclase_.oligoclase.","CO2","clorite","cloritóide","quartzo.feldspato","SO3","cloritóide.clorite","calcite","dolomite","serpentina_.antigorite.crisótilo.","mica_.biotite.moscovite.","feldspato","Fe2O3","plagioclase_ácida","cristobalite","rocha_nome_1","Ferramentas","Binder","LM","graf","WC","T","sigma","epsilon","m","E","H"
  "1","A-010-13","estremoz","ECE-E1",5,26,1430,5,6.08,-0.0981,57,720,23.5,0.9,3.5,162,197.2,5,"ECE-A-010-13-Estremoz_1",2,"sedimentares ","calcário",960,767,276,2711,0.07,0.18,11.5,3.4,57.5,48,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"A-010/13","A-038/11","LM 156",0,0,800,425,0.0062,1.09,159,2085
  "2","A-010-13","estremoz","ECE-E1",5,26,1430,5,5.9,-0.0981,63,720,23.5,0.9,3.5,157,197.2,5,"ECE-A-010-13-Estremoz_1",2,"sedimentares ","calcário",960,767,276,2711,0.07,0.18,11.5,3.4,57.5,48,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"A-010/13","A-038/11","LM 156",0,0,800,425,0.0062,1.09,159,2085
  </code></pre>