Row#

Row#

class pystarburst.row.Row(*values: Any, **named_values: Any)#

Bases: tuple

Represents a row in DataFrame.

It is immutable and works like a tuple or a named tuple.

>>> row = Row(1, 2)
>>> row
Row(1, 2)
>>> row[0]
1
>>> len(row)
2
>>> row[0:1]
Row(1)
>>> named_row = Row(name1=1, name2=2)
>>> named_row
Row(name1=1, name2=2)
>>> named_row["name1"]
1
>>> named_row.name1
1
>>> row == named_row
True

A Row object is callable. You can use it to create other Row objects:

>>> Employee = Row("name", "salary")
>>> emp1 = Employee("John", 10000)
>>> emp1
Row(name='John', salary=10000)
>>> emp2 = Employee("James", 20000)
>>> emp2
Row(name='James', salary=20000)
asDict(recursive: bool = False) Dict#

Convert to a dict if this row object has both keys and values.

asDict() is an alias of as_dict().

Parameters:

recursive – Recursively convert child Row objects to dicts. Default is False.

>>> row = Row(name1=1, name2=2, name3=Row(childname=3))
>>> row.as_dict()
{'name1': 1, 'name2': 2, 'name3': Row(childname=3)}
>>> row.as_dict(True)
{'name1': 1, 'name2': 2, 'name3': {'childname': 3}}
as_dict(recursive: bool = False) Dict#

Convert to a dict if this row object has both keys and values.

asDict() is an alias of as_dict().

Parameters:

recursive – Recursively convert child Row objects to dicts. Default is False.

>>> row = Row(name1=1, name2=2, name3=Row(childname=3))
>>> row.as_dict()
{'name1': 1, 'name2': 2, 'name3': Row(childname=3)}
>>> row.as_dict(True)
{'name1': 1, 'name2': 2, 'name3': {'childname': 3}}