pyspark.sql.DataFrame.first#

DataFrame.first()[source]#

Returns the first row as a Row.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Returns
Row

First row if DataFrame is not empty, otherwise None.

Examples

>>> df = spark.createDataFrame([
...     (2, "Alice"), (5, "Bob")], schema=["age", "name"])
>>> df.first()
Row(age=2, name='Alice')