spark-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mich Talebzadeh <mich.talebza...@gmail.com>
Subject The equivalent of Scala mapping in Pyspark
Date Tue, 13 Oct 2020 22:46:34 GMT
Hi,

I generate an array of random data and create a DF in Spark scala as follows

val end = start + numRows - 1
println (" starting at ID = " + start + " , ending on = " +  end )
val usedFunctions = new UsedFunctions

*val text = ( start to end ).map(i =>*
*             (*
*                 i.toString*
*               , usedFunctions.clustered(i,numRows).toString*
*               , usedFunctions.scattered(i,numRows).toString*
*               , usedFunctions.randomised(i,numRows).toString*
*               , usedFunctions.randomString(chars.mkString(""),50)*
*               , usedFunctions.padString(i, " ", 50)*
*               , usedFunctions.padSingleChar("x ", 4000)*
*             )*
*           ).*
*    toArray*

then I create a DF
val df = sc.parallelize(text).
                              map(p => columns(
                                                  p._1.toString.toInt
                                                , p._2.toString.toDouble
                                                , p._3.toString.toDouble
                                                , p._4.toString.toDouble
                                                , p._5.toString
                                                , p._6.toString
                                                , p._7.toString
                                              )
                                 ).
    toDF


What is the equivalent of this in Pyspark, especially the first part val
text = ..


Thanks


Mich


 *Disclaimer:* Use it at your own risk. Any and all responsibility for any
loss, damage or destruction of data or any other property which may arise
from relying on this email's technical content is explicitly disclaimed.
The author will in no case be liable for any monetary damages arising from
such loss, damage or destruction.

Mime
View raw message