Edit page in Livemark
(2022-09-19 18:33)

Row Steps

These steps are row-based including row filtering, slicing, and many more.

Filter Rows

This step filters rows based on a provided formula or function.

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Resource(path="transform.csv")
target = transform(
    source,
    steps=[
        steps.table_normalize(),
        steps.row_filter(formula="id > 1"),
    ]
)
print(target.schema)
print(target.to_view())
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'}]}
+----+----------+------------+
| id | name     | population |
+====+==========+============+
|  2 | 'france' |         66 |
+----+----------+------------+
|  3 | 'spain'  |         47 |
+----+----------+------------+

Reference

steps.row_filter (class)

steps.row_filter (class)

Filter rows

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, formula: Optional[Any] = None, function: Optional[Any] = None) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • formula (Optional[Any])
  • function (Optional[Any])

steps.row_filter.formula (property)

NOTE: add docs

Signature

Optional[Any]

steps.row_filter.function (property)

NOTE: add docs

Signature

Optional[Any]

Search Rows

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Resource(path="transform.csv")
target = transform(
    source,
    steps=[
        steps.row_search(regex=r"^f.*"),
    ]
)
print(target.schema)
print(target.to_view())
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'}]}
+----+----------+------------+
| id | name     | population |
+====+==========+============+
|  2 | 'france' |         66 |
+----+----------+------------+

Reference

Search rows

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, regex: str, field_name: Optional[str] = None, negate: bool = False) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • regex (str)
  • field_name (Optional[str])
  • negate (bool)

steps.row_search.regex (property)

NOTE: add docs

Signature

str

steps.row_search.field_name (property)

NOTE: add docs

Signature

Optional[str]

steps.row_search.negate (property)

NOTE: add docs

Signature

bool

Slice Rows

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Resource(path="transform.csv")
target = transform(
    source,
    steps=[
        steps.row_slice(head=2),
    ]
)
print(target.schema)
print(target.to_view())
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'}]}
+----+-----------+------------+
| id | name      | population |
+====+===========+============+
|  1 | 'germany' |         83 |
+----+-----------+------------+
|  2 | 'france'  |         66 |
+----+-----------+------------+

Reference

steps.row_slice (class)

steps.row_slice (class)

Slice rows

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, start: Optional[int] = None, stop: Optional[int] = None, step: Optional[int] = None, head: Optional[int] = None, tail: Optional[int] = None) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • start (Optional[int])
  • stop (Optional[int])
  • step (Optional[int])
  • head (Optional[int])
  • tail (Optional[int])

steps.row_slice.start (property)

NOTE: add docs

Signature

Optional[int]

steps.row_slice.stop (property)

NOTE: add docs

Signature

Optional[int]

steps.row_slice.step (property)

NOTE: add docs

Signature

Optional[int]

steps.row_slice.head (property)

NOTE: add docs

Signature

Optional[int]

steps.row_slice.tail (property)

NOTE: add docs

Signature

Optional[int]

Sort Rows

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Resource(path="transform.csv")
target = transform(
    source,
    steps=[
        steps.row_sort(field_names=["name"]),
    ]
)
print(target.schema)
print(target.to_view())
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'}]}
+----+-----------+------------+
| id | name      | population |
+====+===========+============+
|  2 | 'france'  |         66 |
+----+-----------+------------+
|  1 | 'germany' |         83 |
+----+-----------+------------+
|  3 | 'spain'   |         47 |
+----+-----------+------------+

Reference

steps.row_sort (class)

steps.row_sort (class)

Sort rows

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, field_names: List[str], reverse: bool = False) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • field_names (List[str])
  • reverse (bool)

steps.row_sort.field_names (property)

NOTE: add docs

Signature

List[str]

steps.row_sort.reverse (property)

NOTE: add docs

Signature

bool

Split Rows

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Resource(path="transform.csv")
target = transform(
    source,
    steps=[
        steps.row_split(field_name="name", pattern="a"),
    ]
)
print(target.schema)
print(target.to_view())
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'}]}
+----+--------+------------+
| id | name   | population |
+====+========+============+
|  1 | 'germ' |         83 |
+----+--------+------------+
|  1 | 'ny'   |         83 |
+----+--------+------------+
|  2 | 'fr'   |         66 |
+----+--------+------------+
|  2 | 'nce'  |         66 |
+----+--------+------------+
|  3 | 'sp'   |         47 |
+----+--------+------------+
...

Reference

steps.row_split (class)

steps.row_split (class)

Split rows

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, pattern: str, field_name: str) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • pattern (str)
  • field_name (str)

steps.row_split.pattern (property)

NOTE: add docs

Signature

str

steps.row_split.field_name (property)

NOTE: add docs

Signature

str

Subset Rows

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Resource(path="transform.csv")
target = transform(
    source,
    steps=[
        steps.field_update(name="id", value=1),
        steps.row_subset(subset="conflicts", field_name="id"),
    ]
)
print(target.schema)
print(target.to_view())
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'}]}
+----+-----------+------------+
| id | name      | population |
+====+===========+============+
|  1 | 'germany' |         83 |
+----+-----------+------------+
|  1 | 'france'  |         66 |
+----+-----------+------------+
|  1 | 'spain'   |         47 |
+----+-----------+------------+

Reference

steps.row_subset (class)

steps.row_subset (class)

Subset rows

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, subset: str, field_name: Optional[str] = None) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • subset (str)
  • field_name (Optional[str])

steps.row_subset.subset (property)

NOTE: add docs

Signature

str

steps.row_subset.field_name (property)

NOTE: add docs

Signature

Optional[str]

Ungroup Rows

Example

from pprint import pprint
from frictionless import Package, Resource, transform, steps

source = Resource(path="transform-groups.csv")
target = transform(
    source,
    steps=[
        steps.row_ungroup(group_name="name", selection="first"),
    ]
)
print(target.schema)
print(target.to_view())
{'fields': [{'name': 'id', 'type': 'integer'},
            {'name': 'name', 'type': 'string'},
            {'name': 'population', 'type': 'integer'},
            {'name': 'year', 'type': 'integer'}]}
+----+-----------+------------+------+
| id | name      | population | year |
+====+===========+============+======+
|  3 | 'france'  |         66 | 2020 |
+----+-----------+------------+------+
|  1 | 'germany' |         83 | 2020 |
+----+-----------+------------+------+
|  5 | 'spain'   |         47 | 2020 |
+----+-----------+------------+------+

Reference

steps.row_ungroup (class)

steps.row_ungroup (class)

Ungroup rows

Signature

(*, title: Optional[str] = None, description: Optional[str] = None, selection: str, group_name: str, value_name: Optional[str] = None) -> None

Parameters
  • title (Optional[str])
  • description (Optional[str])
  • selection (str)
  • group_name (str)
  • value_name (Optional[str])

steps.row_ungroup.selection (property)

NOTE: add docs

Signature

str

steps.row_ungroup.group_name (property)

NOTE: add docs

Signature

str

steps.row_ungroup.value_name (property)

NOTE: add docs

Signature

Optional[str]

It's a beta version of Frictionless Framework (v5). Read Frictionless Framework (v4) docs for a version that is currently installed by default by pip.