Reputation: 1380
I am getting this exception if I use the following code :
int() argument must be a string or a number, not 'Column'
df= df.withColumn('FY',
F.when((df['ID'].substr(5,2).isin({'11','12'})),int(df['ID'].substr(1,4))+1).
otherwise(int(df['ID'].substr(1,4))))
Basically I want to add 1 to the result if the result isin 11 or 12 otherwise just uder the ID. Please help, I am fairly new to Python.
Upvotes: 3
Views: 1580
Reputation:
Use:
df.withColumn('FY',F.when(df['ID'].substr(5,2).isin({'11','12'}),
df['ID'].substr(1,4).cast("integer") + 1).
otherwise(df['ID'].substr(1,4)).cast("integer"))
Upvotes: 2