Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python spark将dataframe列数据类型更改为int错误_Python_Apache Spark_Types_Casting - Fatal编程技术网

python spark将dataframe列数据类型更改为int错误

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

我想将列类型转换为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 <= 3")
在最新版本中,
rowNumber
功能也已被删除。您应该使用
rowNumber
以实现向前兼容性

TypeError: unorderable types: str() <= int()
"rn" <= 3
.where("rn <= 3")
from pyspark.sql.functions import col

.where(col("rn") <= 3)