如何获得最后一行。
假设所有列都可修改的漫长而丑陋的方式:
from pyspark.sql.functions import ( col, max as max_, struct, monotonically_increasing_id)last_row = (df .withColumn("_id", monotonically_increasing_id()) .select(max(struct("_id", *df.columns)) .alias("tmp")).select(col("tmp.*")) .drop("_id"))
如果不是所有列都可以订购,则可以尝试:
with_id = df.withColumn("_id", monotonically_increasing_id())i = with_id.select(max_("_id")).first()[0]with_id.where(col("_id") == i).drop("_id")
注意。/
oassql.functions中有last
函数,pyspark.sql.functions`但考虑到对相应表达式的描述,此处不是一个好的选择。
我如何通过index.like访问数据框行
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)