如果我使用以下代码,我会收到此异常:
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 还很陌生。
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"))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)