---
title: Row class
description: "Row class in PySpark: A row in DataFrame. The fields in it can be accessed like attributes (`row.key`) or like dictionary values (`row[key]`)."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/row
---

# Row class

A row in DataFrame. The fields in it can be accessed:

* like attributes (`row.key`)
* like dictionary values (`row[key]`)

`key in row` will search through row keys.

Row can be used to create a row object by using named arguments. It is not allowed to omit a named argument to represent that the value is None or missing. This should be explicitly set to None in this case.

*Changed in Databricks Runtime 7.4*: Rows created from named arguments no longer have field names sorted alphabetically and will be ordered in the position as entered.

## Syntax

```python
from pyspark.sql import Row

Row(tuple)
```

## Parameters

| Parameter | Type  | Description      |
| --------- | ----- | ---------------- |
| `tuple`   | tuple | The row elements |

## Methods

| Method                                                                                            | Description                          |
| ------------------------------------------------------------------------------------------------- | ------------------------------------ |
| [`asDict(recursive)`](https://docs.databricks.com/aws/en/pyspark/reference/classes/row/asDict.md) | Returns the Row as `Dict[str, Any]`. |

## Examples

### Using named arguments

```python
from pyspark.sql import Row
row = Row(name="Alice", age=11)
row
# Row(name='Alice', age=11)
row['name'], row['age']
# ('Alice', 11)
row.name, row.age
# ('Alice', 11)
'name' in row
# True
'wrong_key' in row
# False
```

### Creating Row classes

Row can also be used to create another Row-like class, then it could be used to create Row objects:

```python
Person = Row("name", "age")
Person
# <Row('name', 'age')>
'name' in Person
# True
'wrong_key' in Person
# False
Person("Alice", 11)
# Row(name='Alice', age=11)
```

This form can also be used to create rows as tuple values, with unnamed fields:

```python
row1 = Row("Alice", 11)
row2 = Row(name="Alice", age=11)
row1 == row2
# True
```
