获取int()参数必须是字符串或数字,而不是'Column'-Apache Spark [英] Getting int() argument must be a string or a number, not 'Column'- Apache Spark
本文介绍了获取int()参数必须是字符串或数字,而不是'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))))
基本上,如果结果是11或12,我想在结果中加1,否则只需输入ID.请帮忙,我是Python的新手.
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.
推荐答案
使用:
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"))
这篇关于获取int()参数必须是字符串或数字,而不是'Column'-Apache Spark的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文