I have a pyspark dataframe:
Location Month Year
USA 1 2020
USA 1 2021
CAN 1 2020
CAN 2 2020
CAN 1 2021
CAN 2 2021
I need to combine Month and Year columns to create Date column. My expected dataframe should be:
Location Month Year Date
USA 1 2020 1/1/2020
USA 1 2021 1/1/2021
CAN 1 2020 1/1/2020
CAN 2 2020 2/1/2020
CAN 1 2021 1/1/2021
CAN 2 2021 2/1/2021
All the dates should be starting on 1st of every month. I have tried this code:
df = df.select(concat_ws('/',df.month,1,df.year).alias('Month') \
,df["*"])
and getting this error:
Invalid argument, not a string or column
Both Month and Year columns are of long datatype