title: transpose UDF in pyspark
body: <p>How to create transpose udf in pyspark.
  I have code in scala language, can anyone convert into pyspark.</p>
  <pre><code>def transposeUDF_2(transDF: DataFrame, transBy: Seq[String]): DataFrame = {
        val (cols, types) = transDF.dtypes.filter{ case (c, _) =&gt; !transBy.contains(c)}.unzip
        val kvs = explode(array(
          cols.map(c =&gt; struct(lit(c).alias(&quot;name&quot;), col(c).alias(&quot;value&quot;))): _*
        ))
        val byExprs = transBy.map(col(_))
        transDF
          .select(byExprs :+ kvs.alias(&quot;_kvs&quot;): _*)
          .select(byExprs ++ Seq(col(&quot;_kvs.name&quot;), col(&quot;_kvs.value&quot;)): _*)
      }
  
  </code></pre>
  <p>Thanks!!</p>