“Seq” will be implicitly converted to “DataFrameHolder”, and “toDF” method is defined in “DataFrameHolder”. And there is no such method for Array. So user has to convert explicitly by himself.
implicit def localSeqToDataFrameHolder[A <: Product : TypeTag](data: Seq[A]): DataFrameHolder = { DataFrameHolder(_sqlContext.createDataFrame(data)) } Thanks, William From: Ashok Kumar [mailto:ashok34...@yahoo.com.INVALID] Sent: Wednesday, March 2, 2016 5:06 AM To: Shixiong(Ryan) Zhu Cc: Jeff Zhang; User Subject: Re: Converting array to DF Thanks great val weights = Array(("a", 3), ("b", 2), ("c", 5), ("d", 1), ("e", 9), ("f", 4), ("g", 6)) weights.toSeq.toDF("weights","value").orderBy(desc("value")).collect.foreach(println) On Tuesday, 1 March 2016, 20:52, Shixiong(Ryan) Zhu <shixi...@databricks.com<mailto:shixi...@databricks.com>> wrote: For Array, you need to all `toSeq` at first. Scala can convert Array to ArrayOps automatically. However, it's not a `Seq` and you need to call `toSeq` explicitly. On Tue, Mar 1, 2016 at 1:02 AM, Ashok Kumar <ashok34...@yahoo.com.invalid<mailto:ashok34...@yahoo.com.invalid>> wrote: Thank you sir This works OK import sqlContext.implicits._ val weights = Seq(("a", 3), ("b", 2), ("c", 5), ("d", 1), ("e", 9), ("f", 4), ("g", 6)) weights.toDF("weights","value").orderBy(desc("value")).collect.foreach(println) Please why Array did not work? On Tuesday, 1 March 2016, 8:51, Jeff Zhang <zjf...@gmail.com<mailto:zjf...@gmail.com>> wrote: Change Array to Seq and import sqlContext.implicits._ On Tue, Mar 1, 2016 at 4:38 PM, Ashok Kumar <ashok34...@yahoo.com.invalid<mailto:ashok34...@yahoo.com.invalid>> wrote: Hi, I have this val weights = Array(("a", 3), ("b", 2), ("c", 5), ("d", 1), ("e", 9), ("f", 4), ("g", 6)) weights.toDF("weights","value") I want to convert the Array to DF but I get thisor weights: Array[(String, Int)] = Array((a,3), (b,2), (c,5), (d,1), (e,9), (f,4), (g,6)) <console>:33: error: value toDF is not a member of Array[(String, Int)] weights.toDF("weights","value") I want to label columns and print out the contents in value order please I don't know why I am getting this error Thanks -- Best Regards Jeff Zhang