python spark将dataframe列数据类型更改为int错误
我想将列类型转换为int并获得前3行python spark将dataframe列数据类型更改为int错误,python,apache-spark,types,casting,Python,Apache Spark,Types,Casting,我想将列类型转换为int并获得前3行 df.withColumn("rn", rowNumber().over(windowSpec).cast('int')).where("rn"<=3).drop("rn").show() df.withColumn(“rn”,rowNumber().over(windowSpec).cast('int'))。其中(“rn”错误在这里: .where("rn"<=3) 如果希望它是SQL文本,则应传递一个字符串: .where("rn
df.withColumn("rn", rowNumber().over(windowSpec).cast('int')).where("rn"<=3).drop("rn").show()
df.withColumn(“rn”,rowNumber().over(windowSpec).cast('int'))。其中(“rn”错误在这里:
.where("rn"<=3)
如果希望它是SQL文本,则应传递一个字符串:
.where("rn <= 3")
在最新版本中,rowNumber
功能也已被删除。您应该使用rowNumber
以实现向前兼容性
TypeError: unorderable types: str() <= int()
"rn" <= 3
.where("rn <= 3")
from pyspark.sql.functions import col
.where(col("rn") <= 3)