Skip to content

Commit

Permalink
fix docs as per review & column name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed Apr 7, 2017
1 parent 3df0abe commit 0e9c4a4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
8 changes: 4 additions & 4 deletions doc/source/computation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ 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 ``MultiIndexed DataFrame`` whose ``index`` 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:

Expand All @@ -549,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.unstack(-1).iloc[-50]
covs.loc['2002-09-22':]
.. ipython:: python
correls = df.rolling(window=50).corr()
correls.unstack(-1).iloc[-50]
correls.loc['2002-09-22':]
You can efficiently retrieve the time series of correlations between two
columns using ``.loc`` indexing:
Expand All @@ -567,7 +567,7 @@ columns using ``.loc`` indexing:
.. ipython:: python
@savefig rolling_corr_pairwise_ex.png
correls.unstack(-1).[('A', 'C')].plot()
correls.loc[:, ('A', 'C')].plot()
.. _stats.aggregate:

Expand Down
9 changes: 9 additions & 0 deletions doc/source/dsintro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -788,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),
Expand All @@ -799,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))}
Expand All @@ -821,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')
Expand All @@ -829,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)})
Expand Down Expand Up @@ -856,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)
Expand Down Expand Up @@ -885,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)
Expand Down Expand Up @@ -914,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()
Expand All @@ -928,6 +935,7 @@ 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),
Expand Down Expand Up @@ -964,6 +972,7 @@ support the multi-dimensional analysis that is one of ``Panel`` s main usecases.
Convert to a MultiIndex DataFrame

.. ipython:: python
:okwarning:
p.to_frame()
Expand Down
11 changes: 6 additions & 5 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Highlights include:
- Improved user API when accessing levels in ``.groupby()``, see :ref:`here <whatsnew_0200.enhancements.groupby_access>`
- Improved support for UInt64 dtypes, see :ref:`here <whatsnew_0200.enhancements.uint64_support>`
- A new orient for JSON serialization, ``orient='table'``, that uses the Table Schema spec, see :ref:`here <whatsnew_0200.enhancements.table_schema>`
- Window Binary Corr/Cov operations return a MultiIndex DataFrame rather than a Panel, see :ref:`here <whhatsnew_0200.api_breaking.rolling_pairwise>`
- Window Binary Corr/Cov operations return a MultiIndexed ``DataFrame`` rather than a ``Panel``, as ``Panel`` is now deprecated, see :ref:`here <whatsnew_0200.api_breaking.rolling_pairwise>`
- Support for S3 handling now uses ``s3fs``, see :ref:`here <whatsnew_0200.api_breaking.s3>`
- Google BigQuery support now uses the ``pandas-gbq`` library, see :ref:`here <whatsnew_0200.api_breaking.gbq>`
- Switched the test framework to use `pytest <http://doc.pytest.org/en/latest>`__ (:issue:`13097`)
Expand Down Expand Up @@ -872,8 +872,9 @@ Window Binary Corr/Cov operations return a MultiIndex DataFrame
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A binary window operation, like ``.corr()`` or ``.cov()``, when operating on a ``.rolling(..)``, ``.expanding(..)``, or ``.ewm(..)`` object,
will now return a 2-level ``MultiIndexed DataFrame`` rather than a ``Panel``. These are equivalent in function,
but MultiIndexed DataFrames enjoy more support in pandas.
will now return a 2-level ``MultiIndexed DataFrame`` rather than a ``Panel``, as ``Panel`` is now deprecated,
see :ref:`here <_whatsnew_0200.api_breaking.deprecate_panel>`. These are equivalent in function,
but MultiIndexed ``DataFrame`` s enjoy more support in pandas.
See the section on :ref:`Windowed Binary Operations <stats.moments.binary>` for more information. (:issue:`15677`)

.. ipython:: python
Expand All @@ -883,7 +884,7 @@ See the section on :ref:`Windowed Binary Operations <stats.moments.binary>` for
columns=pd.Index(['A', 'B'], name='bar'),
index=pd.date_range('20160101',
periods=100, freq='D', name='foo'))
df
df.tail()

Old Behavior:

Expand All @@ -902,7 +903,7 @@ New Behavior:
.. ipython:: python

res = df.rolling(12).corr()
res
res.tail()

Retrieving a correlation matrix for a cross-section

Expand Down
6 changes: 4 additions & 2 deletions pandas/core/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1730,9 +1730,11 @@ def dataframe_from_int_dict(data, frame_template):
columns=arg2.columns,
dtype='float64')

# reset our names to arg1 names
# reset our index names to arg1 names
# reset our column names to arg2 names
# careful not to mutate the original names
result.columns = Index(result.columns).set_names(None)
result.columns = Index(result.columns).set_names(
arg2.columns.name)
result.index = result.index.set_names(
[arg1.index.name, arg1.columns.name])

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2751,7 +2751,7 @@ def test_moment_functions_zero_length_pairwise(self):
df2_expected = DataFrame(
index=pd.MultiIndex.from_product([df2.index, df2.columns],
names=['bar', 'foo']),
columns=Index(['a']),
columns=Index(['a'], name='foo'),
dtype='float64')

functions = [lambda x: (x.expanding(min_periods=5)
Expand Down Expand Up @@ -2789,7 +2789,7 @@ def test_expanding_cov_pairwise_diff_length(self):
result3 = df1a.expanding().cov(df2, pairwise=True).loc[2]
result4 = df1a.expanding().cov(df2a, pairwise=True).loc[2]
expected = DataFrame([[-3.0, -6.0], [-5.0, -10.0]],
columns=['A', 'B'],
columns=Index(['A', 'B'], name='foo'),
index=Index(['X', 'Y'], name='foo'))
tm.assert_frame_equal(result1, expected)
tm.assert_frame_equal(result2, expected)
Expand Down

0 comments on commit 0e9c4a4

Please sign in to comment.