Pandas dataframe having an additional "layer" Pandas dataframe having an additional "layer" pandas pandas

Pandas dataframe having an additional "layer"


pandas.DataFrame cannot have 3 dimensions:

DataFrame is a 2-dimensional labeled data structure with columns of potentially different types.

However, there is a way to fake 3-dimensions with MultiIndex / Advanced Indexing:

Hierarchical indexing (MultiIndex)

Hierarchical / Multi-level indexing is very exciting as it opens the door to some quite sophisticated data analysis and manipulation, especially for working with higher dimensional data. In essence, it enables you to store and manipulate data with an arbitrary number of dimensions in lower dimensional data structures like Series (1d) and DataFrame (2d).

If you really need that extra dimension go with pandas.Panel:

Panel is a somewhat less-used, but still important container for 3-dimensional data.

but don't miss this important disclaimer from the docs:

Note: Unfortunately Panel, being less commonly used than Series and DataFrame, has been slightly neglected feature-wise. A number of methods and options available in DataFrame are not available in Panel.

There is also pandas.Panel4D (experimental) in the unlikely chance that you need it.