2024-04-25 20:39:17 发布
网友
我使用pyspark(Python 2.7.9/Spark 1.3.1)并有一个dataframe GroupObject,需要按降序过滤和排序。试图通过这段代码来实现它。
group_by_dataframe.count().filter("`count` >= 10").sort('count', ascending=False)
但它抛出了以下错误。
sort() got an unexpected keyword argument 'ascending'
使用orderBy:
group_by_dataframe.count().filter("`count` >= 10").orderBy('count', ascending=False)
http://spark.apache.org/docs/2.0.0/api/python/pyspark.sql.html
到目前为止,最方便的方法是:
df.orderBy(df.column_name.desc()))
不需要特殊导入或记住如何拼写ascending?
ascending
在PySpark 1.3sort中,方法不接受升序参数。您可以改用desc方法:
sort
desc
from pyspark.sql.functions import col (group_by_dataframe .count() .filter("`count` >= 10") .sort(col("count").desc()))
或desc函数:
from pyspark.sql.functions import desc (group_by_dataframe .count() .filter("`count` >= 10") .sort(desc("count"))
这两种方法都可以在Spark>;=1.3(包括Spark 2.x)时使用。
使用orderBy:
http://spark.apache.org/docs/2.0.0/api/python/pyspark.sql.html
到目前为止,最方便的方法是:
不需要特殊导入或记住如何拼写
ascending
?在PySpark 1.3
sort
中,方法不接受升序参数。您可以改用desc
方法:或
desc
函数:这两种方法都可以在Spark>;=1.3(包括Spark 2.x)时使用。
相关问题 更多 >
编程相关推荐