import pandas as pd
from pandas_datareader import data
Panels β Three-Dimensional Data Structures (Deprecated)ΒΆ
Pandas Panels were three-dimensional data containers (items x major_axis x minor_axis) designed for storing related DataFrames, such as stock price data for multiple companies over time. Panels have been deprecated in favor of MultiIndex DataFrames, which offer the same representational power with better integration into the rest of the Pandas API.
This notebook demonstrates Panel creation from Yahoo Finance data using pandas_datareader, accessing items, major/minor axes, cross-sections with .major_xs() and .minor_xs(), transposing axes, and swapping axes. While Panels are no longer recommended, understanding them helps when reading legacy code, and the underlying concepts of multi-dimensional data access map directly to MultiIndex DataFrames.
companies = ["MSFT","GOOG","AAPL","AMZN"]
p =data.DataReader(name= companies, data_source="yahoo", start="2010", end="2016")
p
p.items
p.major_axis
p.minor_axis
p.axes
p.ndin
p.dtypes
p.shape
p.shape
p.values
p.items
p["High"]
p['Volume'].head()
p.Close
p.loc["Close","2010-01-04","GOOG"]
p.iloc[4,200]
p.iloc[4,200,2]
p.to_frame()
p.items
p.major_axis
p.major_xs("2015-12-31")
p
p.minor_axis
p.minor_xs('AAPL')
p.axes
p2 = p.transpose(2,1,0)
p2
p2.major_axis
p.major_axis
p2.minor_axis
p.minor_axis
p2['GOOG']
p2 = p.swapaxes("items","minor")
p2
p2['MSFT']