Reshaping Data#
We’ve already covered how to sort or group by values in a dataframe. We can also perform more drastic data manipulations and transformations using pandas
.
A digest of these operations, courtesty of Pandas documentation:
pandas.pivot
andpandas.pivot_table
: Group unique values within one or more discrete categories.DataFrame.stack
andDataFrame.unstack
: Pivot a column or row level to the opposite axis respectively.pandas.melt
andpandas.wide_to_long
: Unpivot a wideDataFrame
to a long format.pandas.get_dummies
andpandas.from_dummies
: Conversions with indicator variables.Series.explode
: Convert a column of list-like values to individual rows.pandas.crosstab
: Calculate a cross-tabulation of multiple 1 dimensional factor arrays.pandas.cut
: Transform continuous variables to discrete, categorical valuespandas.factorize
: Encode 1 dimensional variables into integer labels.
We’ll cover some of these workflows in greater depth.
Hierarchical Indexing, or MultiIndex#
As part of these workflows, we’ll see the different ways Pandas
supports hierarchical indexing, sometimes called a multi-index.
Multiple rows or columns can be part of a DataFrame
’s indices.
For more detailed information: