-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DEPR: Panel deprecated #15601
DEPR: Panel deprecated #15601
Changes from all commits
84e788b
f41d3df
6b20ddc
cd5b6b8
a2625ba
912d523
538b8e8
d04db2e
755606d
3df0abe
0e9c4a4
c39453a
fa136dd
f8800dc
04104a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,13 +505,18 @@ two ``Series`` or any combination of ``DataFrame/Series`` or | |
- ``DataFrame/DataFrame``: by default compute the statistic for matching column | ||
names, returning a DataFrame. If the keyword argument ``pairwise=True`` is | ||
passed then computes the statistic for each pair of columns, returning a | ||
``Panel`` whose ``items`` are the dates in question (see :ref:`the next section | ||
``MultiIndexed DataFrame`` whose ``index`` are the dates in question (see :ref:`the next section | ||
<stats.moments.corr_pairwise>`). | ||
|
||
For example: | ||
|
||
.. ipython:: python | ||
|
||
df = pd.DataFrame(np.random.randn(1000, 4), | ||
index=pd.date_range('1/1/2000', periods=1000), | ||
columns=['A', 'B', 'C', 'D']) | ||
df = df.cumsum() | ||
|
||
df2 = df[:20] | ||
df2.rolling(window=5).corr(df2['B']) | ||
|
||
|
@@ -520,11 +525,16 @@ For example: | |
Computing rolling pairwise covariances and correlations | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. warning:: | ||
|
||
Prior to version 0.20.0 if ``pairwise=True`` was passed, a ``Panel`` would be returned. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not only in the case of pairwise I think? (every rolling corr returned a Panel, eg There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What confused me here is that you don't need to pass this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, this is implicit |
||
This will now return a 2-level MultiIndexed DataFrame, see the whatsnew :ref:`here <whatsnew_0200.api_breaking.rolling_pairwise>` | ||
|
||
In financial data analysis and other fields it's common to compute covariance | ||
and correlation matrices for a collection of time series. Often one is also | ||
interested in moving-window covariance and correlation matrices. This can be | ||
done by passing the ``pairwise`` keyword argument, which in the case of | ||
``DataFrame`` inputs will yield a ``Panel`` whose ``items`` are the dates in | ||
``DataFrame`` inputs will yield a MultiIndexed ``DataFrame`` whose ``index`` are the dates in | ||
question. In the case of a single DataFrame argument the ``pairwise`` argument | ||
can even be omitted: | ||
|
||
|
@@ -539,12 +549,12 @@ can even be omitted: | |
.. ipython:: python | ||
|
||
covs = df[['B','C','D']].rolling(window=50).cov(df[['A','B','C']], pairwise=True) | ||
covs[df.index[-50]] | ||
covs.loc['2002-09-22':] | ||
|
||
.. ipython:: python | ||
|
||
correls = df.rolling(window=50).corr() | ||
correls[df.index[-50]] | ||
correls.loc['2002-09-22':] | ||
|
||
You can efficiently retrieve the time series of correlations between two | ||
columns using ``.loc`` indexing: | ||
|
@@ -557,7 +567,7 @@ columns using ``.loc`` indexing: | |
.. ipython:: python | ||
|
||
@savefig rolling_corr_pairwise_ex.png | ||
correls.loc[:, 'A', 'C'].plot() | ||
correls.loc[:, ('A', 'C')].plot() | ||
|
||
.. _stats.aggregate: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -763,6 +763,11 @@ completion mechanism so they can be tab-completed: | |
Panel | ||
----- | ||
|
||
.. warning:: | ||
|
||
In 0.20.0, ``Panel`` is deprecated and will be removed in | ||
a future version. See the section :ref:`Deprecate Panel <dsintro.deprecate_panel>`. | ||
|
||
Panel is a somewhat less-used, but still important container for 3-dimensional | ||
data. The term `panel data <http://en.wikipedia.org/wiki/Panel_data>`__ is | ||
derived from econometrics and is partially responsible for the name pandas: | ||
|
@@ -783,6 +788,7 @@ From 3D ndarray with optional axis labels | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
wp = pd.Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'], | ||
major_axis=pd.date_range('1/1/2000', periods=5), | ||
|
@@ -794,6 +800,7 @@ From dict of DataFrame objects | |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
data = {'Item1' : pd.DataFrame(np.random.randn(4, 3)), | ||
'Item2' : pd.DataFrame(np.random.randn(4, 2))} | ||
|
@@ -816,6 +823,7 @@ dictionary of DataFrames as above, and the following named parameters: | |
For example, compare to the construction above: | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
pd.Panel.from_dict(data, orient='minor') | ||
|
||
|
@@ -824,6 +832,7 @@ DataFrame objects with mixed-type columns, all of the data will get upcasted to | |
``dtype=object`` unless you pass ``orient='minor'``: | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
df = pd.DataFrame({'a': ['foo', 'bar', 'baz'], | ||
'b': np.random.randn(3)}) | ||
|
@@ -851,6 +860,7 @@ This method was introduced in v0.7 to replace ``LongPanel.to_long``, and convert | |
a DataFrame with a two-level index to a Panel. | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
midx = pd.MultiIndex(levels=[['one', 'two'], ['x','y']], labels=[[1,1,0,0],[1,0,1,0]]) | ||
df = pd.DataFrame({'A' : [1, 2, 3, 4], 'B': [5, 6, 7, 8]}, index=midx) | ||
|
@@ -880,6 +890,7 @@ A Panel can be rearranged using its ``transpose`` method (which does not make a | |
copy by default unless the data are heterogeneous): | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
wp.transpose(2, 0, 1) | ||
|
||
|
@@ -909,6 +920,7 @@ Squeezing | |
Another way to change the dimensionality of an object is to ``squeeze`` a 1-len object, similar to ``wp['Item1']`` | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
wp.reindex(items=['Item1']).squeeze() | ||
wp.reindex(items=['Item1'], minor=['B']).squeeze() | ||
|
@@ -923,12 +935,55 @@ for more on this. To convert a Panel to a DataFrame, use the ``to_frame`` | |
method: | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
panel = pd.Panel(np.random.randn(3, 5, 4), items=['one', 'two', 'three'], | ||
major_axis=pd.date_range('1/1/2000', periods=5), | ||
minor_axis=['a', 'b', 'c', 'd']) | ||
panel.to_frame() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All those example above will need a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually had to add about 10 :> |
||
|
||
|
||
.. _dsintro.deprecate_panel: | ||
|
||
Deprecate Panel | ||
--------------- | ||
|
||
Over the last few years, pandas has increased in both breadth and depth, with new features, | ||
datatype support, and manipulation routines. As a result, supporting efficient indexing and functional | ||
routines for ``Series``, ``DataFrame`` and ``Panel`` has contributed to an increasingly fragmented and | ||
difficult-to-understand codebase. | ||
|
||
The 3-d structure of a ``Panel`` is much less common for many types of data analysis, | ||
than the 1-d of the ``Series`` or the 2-D of the ``DataFrame``. Going forward it makes sense for | ||
pandas to focus on these areas exclusively. | ||
|
||
Oftentimes, one can simply use a MultiIndex ``DataFrame`` for easily working with higher dimensional data. | ||
|
||
In additon, the ``xarray`` package was built from the ground up, specifically in order to | ||
support the multi-dimensional analysis that is one of ``Panel`` s main usecases. | ||
`Here is a link to the xarray panel-transition documentation <http://xarray.pydata.org/en/stable/pandas.html#panel-transition>`__. | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
p = tm.makePanel() | ||
p | ||
|
||
Convert to a MultiIndex DataFrame | ||
|
||
.. ipython:: python | ||
:okwarning: | ||
|
||
p.to_frame() | ||
|
||
Alternatively, one can convert to an xarray ``DataArray``. | ||
|
||
.. ipython:: python | ||
|
||
p.to_xarray() | ||
|
||
You can see the full-documentation for the `xarray package <http://xarray.pydata.org/en/stable/>`__. | ||
|
||
.. _dsintro.panelnd: | ||
.. _dsintro.panel4d: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove the backticks here ('MultiIndexed DataFrame' is not on object)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done