reshape
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| Crosstab datacook.engine.ops.reshape `pd.crosstab([df["a"], ...], df["b"])`: counts per combination of values. |
||
| Pivot datacook.engine.ops.reshape `df.pivot_table(...)`: one value column, one column whose values become columns. |
||
| Transpose datacook.engine.ops.reshape Rows become columns: `df.set_index("name").transpose().reset_index(names\="column")`. |
||
| Unpivot datacook.engine.ops.reshape |
🛈 DocStrings¶
Reshape ops: unpivot (melt), pivot table, frequency table (crosstab), transpose.
Results have no index (like every frame here): row labels become columns
(.reset_index()), and column labels made from values (pivot, crosstab, transpose) become
text (.rename(columns=str)), so later steps can name them.
Crosstab
¶
Bases: Op
pd.crosstab([df["a"], ...], df["b"]): counts per combination of values.
Source code in src/datacook/engine/ops/reshape.py
Pivot
¶
Bases: CallOp
df.pivot_table(...): one value column, one column whose values become columns.
Source code in src/datacook/engine/ops/reshape.py
Transpose
¶
Bases: Op
Rows become columns: df.set_index("name").transpose().reset_index(names="column").