3/12/2024 0 Comments Pyspark udf example![]() You can also use other columns as condition like the 'id' column df = df.withColumn("text_title",F.when(F.col('id')>2,F.initcap(F.col('text'))).otherwise(F. Try this: import as Fĭf = df.withColumn('text_title',title_udf('text',F.lit(True)))Īs indicated by in the comment, if this output is your ultimate purpose, ,then you can do this without a udf using initcap() function df = df.withColumn("text_title",F.when(F.lit(True),F.initcap(F.col('text'))).otherwise(F.col('text'))) ![]() ![]() Also your udf definition has to be corrected. So to pass a fixed argument you have to use lit() function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |