How to unpivot with two column via pyspark
df = spark.read.format("csv").option("header","True").load("file:///home/cloudera/indf.txt")
df.show()
dfr = df.select("Id",explode(array([struct(lit(c).alias("colName"),col(c).alias("colVal")) for c in df.columns])))
dfr.show()
dfs = dfr.select("Id","col.*").filter(col("colName")!="Id")
dfs.show()
Comments
Post a Comment