Ordering
- class order.DataFrameOrdering
Ordering specification of a
DataFrame
.- __getitem__(rows)
Return a slice of
DataFrame
in the specified order.- Parameters
rows (slice) – slice: number of first rows
- Returns
DataFrame
with the rows in order- Return type
Example
>>> rows = [(4,), (3,), (2,), (1,)] >>> df = db.create_dataframe(rows=rows, column_names=["id"]) >>> df.order_by("id")[:] ---- id ---- 1 2 3 4 ---- (4 rows)
- order_by(column_name, ascending=None, nulls_first=None, operator=None)
Refine the order by adding another order definition to break the tie.
- Parameters
column_name (str) – name of the column to order the GreenplumPython DataFrame by
ascending (Optional[bool]) – Optional[Bool]: Define ascending of order, True = ASC / False = DESC
nulls_first (Optional[bool]) – Optional[bool]: Define if nulls will be ordered first or last, True = First / False = Last
operator (Optional[str]) – Optional[str]: Define the order with the operator. Can’t be combined with ascending.
- Returns
DataFrame
ordered by the given arguments- Return type
Example
>>> rows = [(1, 2), (1, 3), (2, 2), (3, 1), (3, 4)] >>> t = db.create_dataframe(rows=rows, column_names=["id", "num"]) >>> ret = t.order_by("id").order_by("num", ascending=False)[:5] >>> t.order_by("id").order_by("num", ascending=False)[:] ---------- id | num ----+----- 1 | 3 1 | 2 2 | 2 3 | 4 3 | 1 ---------- (5 rows)