melt | teradatamlspk | pyspark2teradataml - melt - Teradata Package for Python

Teradata® pyspark2teradataml User Guide

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for Python
Release Number
20.00
Published
March 2024
Language
English (United States)
Last Update
2024-04-11
dita:mapPath
oeg1710443196055.ditamap
dita:ditavalPath
ayr1485454803741.ditaval
dita:id
oeg1710443196055
Product Category
Teradata Vantage

In teradatamlspk, the output column name for the columns passed as column expression to melt is different in the output DataFrame compared with PySpark.

PySpark

>>> df.melt(df.accounts, [(df.Jan*2)+df.Feb], "var", "val").show()
+----------+-----------------+-----+
|  accounts|              var|  val|
+----------+-----------------+-----+
|   Red Inc|((Jan * 2) + Feb)|500.0|
|  Alpha Co|((Jan * 2) + Feb)|610.0|
|Yellow Inc|((Jan * 2) + Feb)| NULL|
|Orange Inc|((Jan * 2) + Feb)| NULL|
|  Blue Inc|((Jan * 2) + Feb)|190.0|
| Jones LLC|((Jan * 2) + Feb)|500.0|
+----------+-----------------+-----+

teradatamlspk

>>> df.melt(df.accounts, [(df.Jan*2)+df.Feb], "var", "val").show()
+----------+-------------+-----+
|  accounts|          var|  val|
+----------+-------------+-----+
|   Red Inc|Jan * 2 + Feb|500.0|
|  Alpha Co|Jan * 2 + Feb|610.0|
|Yellow Inc|Jan * 2 + Feb| None|
|Orange Inc|Jan * 2 + Feb| None|
|  Blue Inc|Jan * 2 + Feb|190.0|
| Jones LLC|Jan * 2 + Feb|500.0|
+----------+-------------+-----+