Skip to content
Advertisement

Storing 3-dimensional data in pandas DataFrame

I am new to Python and I’m trying to understand how to manipulate data with pandas DataFrames. I searched for similar questions but I don’t see any satisfying my exact need. Please point me to the correct post if this is a duplicate.

So I have multiple DataFrames with the exact same shape, columns and index. How do I combine them with labels so I can easily access the data with any column/index/label?

E.g. after the setup below, how do I put df1 and df2 into one DataFrame and label them with the names ‘df1’ and ‘df2’, so I can access data in a way like df[‘A’][‘df1’][‘b’], and get number of rows of df?

JavaScript

Advertisement

Answer

I think MultiIndex DataFrame is answer created by concat:

JavaScript

Then for basic select is possible use xs:

JavaScript

And for select index and columns together use slicers:

JavaScript

Another possible solution is use panels.

But in newer versions of pandas is deprecated.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement