Skip to content

Commit

Permalink
docs(python): Clarify behavior of DataFrame.rows_by_key (#14149)
Browse files Browse the repository at this point in the history
Co-authored-by: alexander-beedie <alexander.m.beedie@icloud.com>
  • Loading branch information
BGR360 and alexander-beedie authored Feb 9, 2024
1 parent f6bbbdc commit c14e87f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -9580,6 +9580,10 @@ def rows(
"""
Returns all data in the DataFrame as a list of rows of python-native values.
By default, each row is returned as a tuple of values given in the same order
as the frame columns. Setting `named=True` will return rows of dictionaries
instead.
Parameters
----------
named
Expand All @@ -9598,12 +9602,13 @@ def rows(
--------
Row-iteration is not optimal as the underlying data is stored in columnar form;
where possible, prefer export via one of the dedicated export/output methods.
Where possible you should also consider using `iter_rows` instead to avoid
materialising all the data at once.
You should also consider using `iter_rows` instead, to avoid materialising all
the data at once; there is little performance difference between the two, but
peak memory can be reduced if processing rows in batches.
Returns
-------
list of tuples (default) or dictionaries of row values
list of row value tuples (default), or list of dictionaries (if `named=True`).
See Also
--------
Expand Down Expand Up @@ -9643,7 +9648,10 @@ def rows_by_key(
unique: bool = False,
) -> dict[Any, Iterable[Any]]:
"""
Returns DataFrame data as a keyed dictionary of python-native values.
Returns all data as a dictionary of python-native values keyed by some column.
This method is like `rows`, but instead of returning rows in a flat list, rows
are grouped by the values in the `key` column(s) and returned as a dictionary.
Note that this method should not be used in place of native operations, due to
the high cost of materializing all frame data out into a dictionary; it should
Expand Down

0 comments on commit c14e87f

Please sign in to comment.