@@ -637,6 +637,81 @@ to :ref:`merging/joining functionality <merging>`:
637637 s
638638 s.map(t)
639639
640+
641+ .. _basics.apply_panel :
642+
643+ Applying with a Panel
644+ ~~~~~~~~~~~~~~~~~~~~~
645+
646+ Applying with a ``Panel `` will pass a ``Series `` to the applied function. If the applied
647+ function returns a ``Series ``, the result of the application will be a ``Panel ``. If the applied function
648+ reduces to a scalar, the result of the application will be a ``DataFrame ``.
649+
650+ .. note ::
651+
652+ Prior to 0.13.1 ``apply `` on a ``Panel `` would only work on ``ufuncs `` (e.g. ``np.sum/np.max ``).
653+
654+ .. ipython :: python
655+
656+ import pandas.util.testing as tm
657+ panel = tm.makePanel(5 )
658+ panel
659+ panel[' ItemA' ]
660+
661+ A transformational apply.
662+
663+ .. ipython :: python
664+
665+ result = panel.apply(lambda x : x* 2 , axis = ' items' )
666+ result
667+ result[' ItemA' ]
668+
669+ A reduction operation.
670+
671+ .. ipython :: python
672+
673+ panel.apply(lambda x : x.dtype, axis = ' items' )
674+
675+ A similar reduction type operation
676+
677+ .. ipython :: python
678+
679+ panel.apply(lambda x : x.sum(), axis = ' major_axis' )
680+
681+ This last reduction is equivalent to
682+
683+ .. ipython :: python
684+
685+ panel.sum(' major_axis' )
686+
687+ A transformation operation that returns a ``Panel ``, but is computing
688+ the z-score across the ``major_axis ``.
689+
690+ .. ipython :: python
691+
692+ result = panel.apply(lambda x : (x- x.mean())/ x.std(), axis = ' major_axis' )
693+ result
694+ result[' ItemA' ]
695+
696+ Apply can also accept multiple axes in the ``axis `` argument. This will pass a
697+ ``DataFrame `` of the cross-section to the applied function.
698+
699+ .. ipython :: python
700+
701+ f = lambda x : (x- x.mean(1 )/ x.std(1 ))
702+
703+ result = panel.apply(f, axis = [' items' ,' major_axis' ])
704+ result
705+ result.loc[:,:,' ItemA' ]
706+
707+ This is equivalent to the following
708+
709+ .. ipython :: python
710+
711+ result = Panel(dict ([ (ax,f(panel.loc[:,:,ax])) for ax in panel.minor_axis ]))
712+ result
713+ result.loc[:,:,' ItemA' ]
714+
640715 .. _basics.reindexing :
641716
642717Reindexing and altering labels
@@ -1066,7 +1141,7 @@ or match a pattern:
10661141
10671142 Series([' 1' , ' 2' , ' 3a' , ' 3b' , ' 03c' ]).str.match(pattern, as_indexer = True )
10681143
1069- The distinction between ``match `` and ``contains `` is strictness: ``match ``
1144+ The distinction between ``match `` and ``contains `` is strictness: ``match ``
10701145relies on strict ``re.match ``, while ``contains `` relies on ``re.search ``.
10711146
10721147.. warning ::
@@ -1078,7 +1153,7 @@ relies on strict ``re.match``, while ``contains`` relies on ``re.search``.
10781153 This old, deprecated behavior of ``match `` is still the default. As
10791154 demonstrated above, use the new behavior by setting ``as_indexer=True ``.
10801155 In this mode, ``match `` is analagous to ``contains ``, returning a boolean
1081- Series. The new behavior will become the default behavior in a future
1156+ Series. The new behavior will become the default behavior in a future
10821157 release.
10831158
10841159Methods like ``match ``, ``contains ``, ``startswith ``, and ``endswith `` take
0 commit comments