<jupyter_start><jupyter_text>* Concat `first_name` and `last_name`. Provide an alias to the derived result as `full_name`<jupyter_code>from pyspark.sql.functions import concat, lit
# Equivalent logic using select
users_df. \
    select(
        'id', 'first_name', 'last_name',
        concat('first_name', lit(', '), 'last_name').alias('full_name')
    ). \
    show()
# A Column whose name is full_name is added by `withColumn`
users_df. \
    select('id', 'first_name', 'last_name'). \
    withColumn('full_name', concat('first_name', lit(', '), 'last_name')). \
    show()
help(users_df.withColumn)
from pyspark.sql.functions import col
users_df. \
    select('id', 'first_name', 'last_name'). \
    withColumn('fn', col('first_name')). \
    show()
users_df. \
    select('id', 'first_name', 'last_name'). \
    withColumn('fn', users_df['first_name']). \
    show()<jupyter_output><empty_output><jupyter_text>* Add another column by name `course_count` where it contain number of courses the user is enrolled for.<jupyter_code>users_df.select('id', 'courses'). \
    show()
users_df.select('id', 'courses'). \
    dtypes
from pyspark.sql.functions import size
users_df.select('id', 'courses'). \
    withColumn('course_count', size('courses')). \
    show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup