cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How can I use display() in a python notebook with pyspark.sql.Row Objects, e.g. after calling the first() operation on a DataFrame?

Anonymous
Not applicable

I'm trying to

display()
the results from calling
first()
on a DataFrame, but
display()
doesn't work with
pyspark.sql.Row
objects. How can I display this result?

2 REPLIES 2

Anonymous
Not applicable

The

display()
function requires a collection as opposed to single item, so any of the following examples will give you a means to displaying the results:

  • `display([df.first()])` # just make it an array
  • display(df.take(1))
    # take w/ 1 is functionally equivalent to first(), but returns a DataFrame
  • display(df.limit(1))
    # I'm not 100% sure this is guaranteed to be ordered, but it's another option to try that returns a DataFrame

dnchari
New Contributor II

Use take()

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group