close

[Solved] AssertionError: col should be Column

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AssertionError: col should be Column in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AssertionError: col should be Column Error Occurs?

Today I get the following error AssertionError: col should be Column in python.

How To Solve AssertionError: col should be Column Error ?

  1. How To Solve AssertionError: col should be Column Error ?

    To Solve AssertionError: col should be Column Error There is already function for that:
    from pyspark.sql.functions import current_date

  2. AssertionError: col should be Column

    To Solve AssertionError: col should be Column Error There is already function for that:
    from pyspark.sql.functions import current_date

Solution 1

How to create a new column in PySpark and fill this column with the date of today?

There is already function for that:

from pyspark.sql.functions import current_date

df.withColumn("date", current_date().cast("string"))

AssertionError: col should be Column

Use literal

from pyspark.sql.functions import lit

df.withColumn("date", lit(str(now)[:10]))

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read