Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting int() argument must be a string or a number, not 'Column'- Apache Spark

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.

like image 585
Amar Singh Avatar asked Nov 19 '25 08:11

Amar Singh


1 Answers

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"))
like image 138
user6022341 Avatar answered Nov 21 '25 22:11

user6022341



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!