Found the answer myself, I was using the latest Pandas v1.2.0, where the panel has been removed from Pandas module 0.25.0 onwards.
print(pd.__version__)
print(np.__version__)
1.2.0
1.19.4
From 0.25.0 / 1.2.0 release notes
Warning: The panel has been fully removed. For N-D labeled data structures, please use xarray
unless you want to use xarray, you need to uninstall and install the version prior to that.
Answer from Jijo John on Stack OverflowAs the Pandas' documentation states, the Panel attribute has been deprecated since version 0.20.0. You are using a version of Pandas (1.2.4) which does not have this attribute anymore. In other words, your code is too old for the version of Pandas in Jupyter Lab.
To solve this, you should follow the documentation and update the code to use either an xarray or a MultiIndex as a replacement to Panel.
Alternatively, a quick and dirty to solve this specific issue is to install a downgraded version of Pandas, but you'll probably have to downgrade a lot of other packages too. So I cannot recommend this option. Anyway, you can do this by adding a cell with this command, before the import and then restarting your notebook environment:
!pip install pandas==0.19.2
I've been struggling with plotly.express and pandas in jupyter notebook as well. I've recently upgraded pandas to 1.3.0 and plolty to 5.1.0.
I had the same error, make sure you upgrade all dependencies as well along with pandas and plotly.
For me this command in the console did the trick:
pip install xarray --upgrade
xarray assignments are not as elegant as the pandas panel. Lets say we want to add a fourth item in the data array above. Here is how it works:
four=xr.DataArray(np.ones((1,4,5)), coords=[['four'],pd.date_range('1/1/2000', periods=4),['a', 'b', 'c', 'd','e']],
dims=['items','major_axis','minor_axis'])
pxc=xr.concat([px,four],dim='items')
Whether the operation is on items or major/minor axis, a similar logic prevails. For deleting use
pxc.drop(['four'], dim='items')
xarray.DataArray is based on a single NumPy array internally, so it cannot be efficiently resized or appended to. Your best option is to make a new, larger DataArray with xarray.concat.
The data structure you're probably looking if you want to add items to a pd.Panel is xarray.Dataset. These are easiest to construct from the multi-indexed DataFrame equivalent to a Panel:
# First, make a DataFrame with a MultiIndex
>>> df = panel.to_frame()
>>> df.head()
one two three
major minor
2000-01-01 a 0.278958 0.676034 -1.544726
b -0.918150 -2.707339 -0.552987
c 0.023479 0.175528 -0.817556
d 1.798001 -0.142016 1.390834
e 0.256575 0.265369 -1.829766
# Now, convert the DataFrame with a MultiIndex to xarray
>>> ds = df.to_xarray()
>>> ds
<xarray.Dataset>
Dimensions: (major: 4, minor: 5)
Coordinates:
* major (major) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03 2000-01-04
* minor (minor) object 'a' 'b' 'c' 'd' 'e'
Data variables:
one (major, minor) float64 0.279 -0.9182 0.02348 1.798 0.2566 2.41 ...
two (major, minor) float64 0.676 -2.707 0.1755 -0.142 0.2654 ...
three (major, minor) float64 -1.545 -0.553 -0.8176 1.391 -1.83 ...
# You can assign a DataFrame if it has the right column/index names
>>> ds['four'] = pd.DataFrame(np.ones((4,5)),
... index=pd.date_range('1/1/2000', periods=4, name='major'),
... columns=pd.Index(['a', 'b', 'c', 'd', 'e'], name='minor'))
# or just pass a tuple directly:
>>> ds['five'] = (('major', 'minor'), np.zeros((4, 5)))
>>> ds
<xarray.Dataset>
Dimensions: (major: 4, minor: 5)
Coordinates:
* major (major) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03 2000-01-04
* minor (minor) object 'a' 'b' 'c' 'd' 'e'
Data variables:
one (major, minor) float64 0.279 -0.9182 0.02348 1.798 0.2566 2.41 ...
two (major, minor) float64 0.676 -2.707 0.1755 -0.142 0.2654 ...
three (major, minor) float64 -1.545 -0.553 -0.8176 1.391 -1.83 ...
four (major, minor) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ...
five (major, minor) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
For more on transitioning from pandas.Panel to xarray, read this section in the xarray docs: http://xarray.pydata.org/en/stable/pandas.html#transitioning-from-pandas-panel-to-xarray