Skip to content

Commit 59ca537

Browse files
committed
adjusted for comments
1 parent b9d0dd3 commit 59ca537

File tree

3 files changed

+37
-57
lines changed

3 files changed

+37
-57
lines changed

pandas/core/frame.py

-27
Original file line numberDiff line numberDiff line change
@@ -5995,33 +5995,6 @@ def _aggregate(self, arg, axis=0, *args, **kwargs):
59955995

59965996
agg = aggregate
59975997

5998-
_transform_doc = dedent("""
5999-
Examples
6000-
--------
6001-
>>> df = pd.DataFrame(np.random.randn(10, 2), columns=['A', 'B'],
6002-
... index=pd.date_range('1/1/2000', periods=10))
6003-
>>> df.iloc[3:7] = np.nan
6004-
6005-
>>> df.transform(lambda x: (x - x.mean()) / x.std())
6006-
A B
6007-
2000-01-01 0.579457 1.236184
6008-
2000-01-02 0.370357 -0.605875
6009-
2000-01-03 1.455756 -0.277446
6010-
2000-01-04 NaN NaN
6011-
2000-01-05 NaN NaN
6012-
2000-01-06 NaN NaN
6013-
2000-01-07 NaN NaN
6014-
2000-01-08 -0.498658 1.274522
6015-
2000-01-09 -0.540524 -1.012676
6016-
2000-01-10 -1.366388 -0.614710
6017-
6018-
See also
6019-
--------
6020-
pandas.DataFrame.aggregate
6021-
pandas.DataFrame.apply
6022-
""")
6023-
6024-
@Appender(_transform_doc)
60255998
@Appender(_shared_docs['transform'] % _shared_doc_kwargs)
60265999
def transform(self, func, axis=0, *args, **kwargs):
60276000
axis = self._get_axis_number(axis)

pandas/core/generic.py

+37-3
Original file line numberDiff line numberDiff line change
@@ -4583,9 +4583,6 @@ def pipe(self, func, *args, **kwargs):
45834583
func : function, string, list of string/functions or dictionary
45844584
Function to use for transforming the data. If a function, must either
45854585
work when passed a %(klass)s or when passed to %(klass)s.apply.
4586-
The function (or each function in a list/dict) must return an
4587-
object with the same length for the provided axis as the
4588-
calling %(klass)s.
45894586
45904587
Accepted combinations are:
45914588
@@ -4606,6 +4603,43 @@ def pipe(self, func, *args, **kwargs):
46064603
Raises
46074604
------
46084605
ValueError: if the returned %(klass)s has a different length than self.
4606+
4607+
Examples
4608+
--------
4609+
>>> df = pd.DataFrame({'A': range(10), 'B': range(10, 0, -1)},
4610+
... index=pd.date_range('1/1/2000', periods=10))
4611+
>>> df.iloc[3:7] = np.nan
4612+
4613+
>>> df.transform(lambda x: (x - x.mean()) / x.std())
4614+
A B
4615+
2000-01-01 -1.143001 1.143001
4616+
2000-01-02 -0.889001 0.889001
4617+
2000-01-03 -0.635001 0.635001
4618+
2000-01-04 NaN NaN
4619+
2000-01-05 NaN NaN
4620+
2000-01-06 NaN NaN
4621+
2000-01-07 NaN NaN
4622+
2000-01-08 0.635001 -0.635001
4623+
2000-01-09 0.889001 -0.889001
4624+
2000-01-10 1.143001 -1.143001
4625+
4626+
It is only required for the axis specified in the ``axis`` parameter
4627+
to have the same length for output and for self. The other axis may have a
4628+
different length:
4629+
4630+
>>> s = pd.Series(range(5))
4631+
>>> s.transform([np.sqrt, np.exp])
4632+
sqrt exp
4633+
0 0.000000 1.000000
4634+
1 1.000000 2.718282
4635+
2 1.414214 7.389056
4636+
3 1.732051 20.085537
4637+
4 2.000000 54.598150
4638+
4639+
See also
4640+
--------
4641+
pandas.%(klass)s.aggregate
4642+
pandas.%(klass)s.apply
46094643
""")
46104644

46114645
# ----------------------------------------------------------------------

pandas/core/series.py

-27
Original file line numberDiff line numberDiff line change
@@ -3100,33 +3100,6 @@ def aggregate(self, func, axis=0, *args, **kwargs):
31003100

31013101
agg = aggregate
31023102

3103-
_transform_doc = dedent("""
3104-
Examples
3105-
--------
3106-
>>> s = pd.Series(range(5))
3107-
>>> s.transform(lambda x: (x - x.mean()) / x.std())
3108-
0 -1.264911
3109-
1 -0.632456
3110-
2 0.000000
3111-
3 0.632456
3112-
4 1.264911
3113-
dtype: float64
3114-
3115-
>>> s.transform([np.sqrt, np.exp])
3116-
sqrt exp
3117-
0 0.000000 1.000000
3118-
1 1.000000 2.718282
3119-
2 1.414214 7.389056
3120-
3 1.732051 20.085537
3121-
4 2.000000 54.598150
3122-
3123-
See also
3124-
--------
3125-
pandas.Series.aggregate
3126-
pandas.Series.apply
3127-
""")
3128-
3129-
@Appender(_transform_doc)
31303103
@Appender(generic._shared_docs['transform'] % _shared_doc_kwargs)
31313104
def transform(self, func, axis=0, *args, **kwargs):
31323105
# Validate the axis parameter

0 commit comments

Comments
 (0)