Skip to content

Commit b7eaacb

Browse files
eldritchideenPingviinituutti
authored andcommitted
DOC: Update Series.apply docstring (pandas-dev#22510)
1 parent 2e844dd commit b7eaacb

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

pandas/core/series.py

+23-20
Original file line numberDiff line numberDiff line change
@@ -3288,23 +3288,27 @@ def transform(self, func, axis=0, *args, **kwargs):
32883288

32893289
def apply(self, func, convert_dtype=True, args=(), **kwds):
32903290
"""
3291-
Invoke function on values of Series. Can be ufunc (a NumPy function
3292-
that applies to the entire Series) or a Python function that only works
3293-
on single values
3291+
Invoke function on values of Series.
3292+
3293+
Can be ufunc (a NumPy function that applies to the entire Series) or a
3294+
Python function that only works on single values.
32943295
32953296
Parameters
32963297
----------
32973298
func : function
3298-
convert_dtype : boolean, default True
3299+
Python function or NumPy ufunc to apply.
3300+
convert_dtype : bool, default True
32993301
Try to find better dtype for elementwise function results. If
3300-
False, leave as dtype=object
3302+
False, leave as dtype=object.
33013303
args : tuple
3302-
Positional arguments to pass to function in addition to the value
3303-
Additional keyword arguments will be passed as keywords to the function
3304+
Positional arguments passed to func after the series value.
3305+
**kwds
3306+
Additional keyword arguments passed to func.
33043307
33053308
Returns
33063309
-------
3307-
y : Series or DataFrame if func returns a Series
3310+
Series or DataFrame
3311+
If func returns a Series object the result will be a DataFrame.
33083312
33093313
See Also
33103314
--------
@@ -3314,12 +3318,11 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
33143318
33153319
Examples
33163320
--------
3317-
33183321
Create a series with typical summer temperatures for each city.
33193322
3320-
>>> series = pd.Series([20, 21, 12], index=['London',
3321-
... 'New York','Helsinki'])
3322-
>>> series
3323+
>>> s = pd.Series([20, 21, 12],
3324+
... index=['London', 'New York', 'Helsinki'])
3325+
>>> s
33233326
London 20
33243327
New York 21
33253328
Helsinki 12
@@ -3329,8 +3332,8 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
33293332
argument to ``apply()``.
33303333
33313334
>>> def square(x):
3332-
... return x**2
3333-
>>> series.apply(square)
3335+
... return x ** 2
3336+
>>> s.apply(square)
33343337
London 400
33353338
New York 441
33363339
Helsinki 144
@@ -3339,7 +3342,7 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
33393342
Square the values by passing an anonymous function as an
33403343
argument to ``apply()``.
33413344
3342-
>>> series.apply(lambda x: x**2)
3345+
>>> s.apply(lambda x: x ** 2)
33433346
London 400
33443347
New York 441
33453348
Helsinki 144
@@ -3350,9 +3353,9 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
33503353
``args`` keyword.
33513354
33523355
>>> def subtract_custom_value(x, custom_value):
3353-
... return x-custom_value
3356+
... return x - custom_value
33543357
3355-
>>> series.apply(subtract_custom_value, args=(5,))
3358+
>>> s.apply(subtract_custom_value, args=(5,))
33563359
London 15
33573360
New York 16
33583361
Helsinki 7
@@ -3363,18 +3366,18 @@ def apply(self, func, convert_dtype=True, args=(), **kwds):
33633366
33643367
>>> def add_custom_values(x, **kwargs):
33653368
... for month in kwargs:
3366-
... x+=kwargs[month]
3369+
... x += kwargs[month]
33673370
... return x
33683371
3369-
>>> series.apply(add_custom_values, june=30, july=20, august=25)
3372+
>>> s.apply(add_custom_values, june=30, july=20, august=25)
33703373
London 95
33713374
New York 96
33723375
Helsinki 87
33733376
dtype: int64
33743377
33753378
Use a function from the Numpy library.
33763379
3377-
>>> series.apply(np.log)
3380+
>>> s.apply(np.log)
33783381
London 2.995732
33793382
New York 3.044522
33803383
Helsinki 2.484907

0 commit comments

Comments
 (0)