"pyspark max of two columns" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "pyspark max of two columns" answered properly. Developers are finding an appropriate answer about pyspark max of two columns related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like pyspark max of two columns. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on pyspark max of two columns.
pyspark max of two columns
from pyspark.sql.types import *
schema = StructType([
StructField("ClientId", IntegerType(), True),
StructField("m_ant21", IntegerType(), True),
StructField("m_ant22", IntegerType(), True),
StructField("m_ant23", IntegerType(), True),
StructField("m_ant24", IntegerType(), True)
])
df = spark\
.createDataFrame(
data=[(0, None, None, None, None),
(1, 23, 13, 17, 99),
(2, 0, 0, 0, 1),
(3, 0, None, 1, 0)],
schema=schema)
import pyspark.sql.functions as F
def agg_to_list(m21,m22,m23,m24):
return [m21,m22,m23,m24]
u_agg_to_list = F.udf(agg_to_list, ArrayType(IntegerType()))
df2 = df.withColumn('all_values', u_agg_to_list('m_ant21', 'm_ant22', 'm_ant23', 'm_ant24'))\
.withColumn('max', F.sort_array("all_values", False)[0])\
.select('ClientId', 'max')
df2.show()
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on pyspark max of two columns can get a collection of related answers to their query. Programmers need to enter their query on pyspark max of two columns related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about pyspark max of two columns for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of pyspark max of two columns while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "pyspark max of two columns". Visit this developer's friendly online web community, CodeProZone, and get your queries like pyspark max of two columns resolved professionally and stay updated to the latest Whatever updates.