Reputation: 5234
I am using PySpark. I have a column that is a date datatype column and another column that is an integer datatype column.
See sample below:
date subtract
2019-01-08 7
2019-01-04 2
I want to create a new column called "new_date" that subtracts the "subtract" column value from the "date" col.
Below is my desired output:
date subtract new_date
2019-01-08 7 2019-01-01
2019-01-04 2 2019-01-02
I tried the code below:
df = df.withColumn('new_date', F.date_sub(df.date, df.subtract))
Below is the error I get: TypeError: 'Column' object is not callable
Upvotes: 1
Views: 1103
Reputation: 11
Try this:
df.withColumn("new_date", F.expr("date_sub(date, subtract)"))
Upvotes: 1