DataBricks 中 pandas.DataFrame.tail 的等价物是什么
What is the equivalent of pandas.DataFrame.tail in DataBricks
DataBricks 中 pandas.DataFrame.tail 的等价物是什么?我在文档中搜索了一下,但没有找到任何相关功能。
DataBricks 显然使用的是 pyspark.sql
数据帧,而不是 pandas
。
# Index the df if you haven't already
# Note that monotonically increasing id has size limits
from pyspark.sql.functions import monotonically_increasing_id
df = df.withColumn("index", monotonically_increasing_id())
# Query with the index
tail = sqlContext.sql("""SELECT * FROM df ORDER BY index DESC limit 5""")
tail.show()
请注意,这很昂贵并且没有发挥 Spark
的优势。
另请参阅:
https://medium.com/@chris_bour/6-differences-between-pandas-and-spark-dataframes-1380cec394d2
DataBricks 中 pandas.DataFrame.tail 的等价物是什么?我在文档中搜索了一下,但没有找到任何相关功能。
DataBricks 显然使用的是 pyspark.sql
数据帧,而不是 pandas
。
# Index the df if you haven't already
# Note that monotonically increasing id has size limits
from pyspark.sql.functions import monotonically_increasing_id
df = df.withColumn("index", monotonically_increasing_id())
# Query with the index
tail = sqlContext.sql("""SELECT * FROM df ORDER BY index DESC limit 5""")
tail.show()
请注意,这很昂贵并且没有发挥 Spark
的优势。
另请参阅:
https://medium.com/@chris_bour/6-differences-between-pandas-and-spark-dataframes-1380cec394d2