How can I convert this expression from pandas to Pyspark Dataframe?
The target is to assign the column date_stamp the value cur
#the data frame is: tag, 2020-06-25 ------------------- 3FMTK1RM 0 678jhgt 18 ####################### vin='3FMTK1RM'# is the first element of tag cur= 5 date_stamp='2020-06-25' df.loc[str(date_stamp),vin] = cur
You can use when:
when
import pyspark.sql.functions as F df2 = df.withColumn( '2020-06-25', F.when(F.col('tag') == 'vin', cur).otherwise(F.col('2020-06-25')) )
1.4m articles
1.4m replys
5 comments
57.0k users