
[英]Is there a way to take the first 1000 rows of a Spark Dataframe?
[英]Displaying samples based on ONLY the first 1000 rows in azure databricks
dfResult = spark.readStream.format("delta").load(PATH)
dfResult.createOrReplaceTempView("Stream")
尝试从增量表中读取流数据,我将所有数据放入其中并通过执行以下操作将它们可视化:
%sql
SELECT Time, score
From Stream
但是,图形或表格中仅显示前 1000 行。
有没有办法查看最后 1000 行或显示整个数据而不是前 1,000 行?
您可以使用 ID 对数据框进行排序并使用 limit() 对其进行子集化,以确保您获得所需的行。
import pyspark.sql.functions as f
# add an index column (if you don't have it)
dfResult = dfResult.withColumn('index', f.monotonically_increasing_id())
# sort ascending and take first 1000 rows for df1
df1 = dfResult.orderBy("index", ascending=True).limit(1000)
# sort descending and take last 1000 rows for df2
df2 = dfResult.orderBy("index", ascending=False).limit(1000)
display(df2)
尝试按日期排序
display(dfResult.orderBy("Time", ascending=False).limit(1000))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.