Skip to content

Commit

Permalink
adjusted for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
topper-123 committed Sep 14, 2018
1 parent 23609c3 commit 650f639
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 57 deletions.
27 changes: 0 additions & 27 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5995,33 +5995,6 @@ def _aggregate(self, arg, axis=0, *args, **kwargs):

agg = aggregate

_transform_doc = dedent("""
Examples
--------
>>> df = pd.DataFrame(np.random.randn(10, 2), columns=['A', 'B'],
... index=pd.date_range('1/1/2000', periods=10))
>>> df.iloc[3:7] = np.nan
>>> df.transform(lambda x: (x - x.mean()) / x.std())
A B
2000-01-01 0.579457 1.236184
2000-01-02 0.370357 -0.605875
2000-01-03 1.455756 -0.277446
2000-01-04 NaN NaN
2000-01-05 NaN NaN
2000-01-06 NaN NaN
2000-01-07 NaN NaN
2000-01-08 -0.498658 1.274522
2000-01-09 -0.540524 -1.012676
2000-01-10 -1.366388 -0.614710
See also
--------
pandas.DataFrame.aggregate
pandas.DataFrame.apply
""")

@Appender(_transform_doc)
@Appender(_shared_docs['transform'] % _shared_doc_kwargs)
def transform(self, func, axis=0, *args, **kwargs):
axis = self._get_axis_number(axis)
Expand Down
40 changes: 37 additions & 3 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4583,9 +4583,6 @@ def pipe(self, func, *args, **kwargs):
func : function, string, list of string/functions or dictionary
Function to use for transforming the data. If a function, must either
work when passed a %(klass)s or when passed to %(klass)s.apply.
The function (or each function in a list/dict) must return an
object with the same length for the provided axis as the
calling %(klass)s.
Accepted combinations are:
Expand All @@ -4606,6 +4603,43 @@ def pipe(self, func, *args, **kwargs):
Raises
------
ValueError: if the returned %(klass)s has a different length than self.
Examples
--------
>>> df = pd.DataFrame({'A': range(10), 'B': range(10, 0, -1)},
... index=pd.date_range('1/1/2000', periods=10))
>>> df.iloc[3:7] = np.nan
>>> df.transform(lambda x: (x - x.mean()) / x.std())
A B
2000-01-01 -1.143001 1.143001
2000-01-02 -0.889001 0.889001
2000-01-03 -0.635001 0.635001
2000-01-04 NaN NaN
2000-01-05 NaN NaN
2000-01-06 NaN NaN
2000-01-07 NaN NaN
2000-01-08 0.635001 -0.635001
2000-01-09 0.889001 -0.889001
2000-01-10 1.143001 -1.143001
It is only required for the axis specified in the ``axis`` parameter
to have the same length for output and for self. The other axis may have a
different length:
>>> s = pd.Series(range(5))
>>> s.transform([np.sqrt, np.exp])
sqrt exp
0 0.000000 1.000000
1 1.000000 2.718282
2 1.414214 7.389056
3 1.732051 20.085537
4 2.000000 54.598150
See also
--------
pandas.%(klass)s.aggregate
pandas.%(klass)s.apply
""")

# ----------------------------------------------------------------------
Expand Down
27 changes: 0 additions & 27 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -3098,33 +3098,6 @@ def aggregate(self, func, axis=0, *args, **kwargs):

agg = aggregate

_transform_doc = dedent("""
Examples
--------
>>> s = pd.Series(range(5))
>>> s.transform(lambda x: (x - x.mean()) / x.std())
0 -1.264911
1 -0.632456
2 0.000000
3 0.632456
4 1.264911
dtype: float64
>>> s.transform([np.sqrt, np.exp])
sqrt exp
0 0.000000 1.000000
1 1.000000 2.718282
2 1.414214 7.389056
3 1.732051 20.085537
4 2.000000 54.598150
See also
--------
pandas.Series.aggregate
pandas.Series.apply
""")

@Appender(_transform_doc)
@Appender(generic._shared_docs['transform'] % _shared_doc_kwargs)
def transform(self, func, axis=0, *args, **kwargs):
# Validate the axis parameter
Expand Down

0 comments on commit 650f639

Please sign in to comment.