#NEWLINE# def apply( self , func , convert_dtype = True , args = ( ) , **kwds ) : #NEWLINE# #INDENT# "\n        Invoke function on values of Series. Can be ufunc (a NumPy function\n        that applies to the entire Series) or a Python function that only works\n        on single values\n\n        Parameters\n        ----------\n        func : function\n        convert_dtype : boolean, default True\n            Try to find better dtype for elementwise function results. If\n            False, leave as dtype=object\n        args : tuple\n            Positional arguments to pass to function in addition to the value\n        Additional keyword arguments will be passed as keywords to the function\n\n        Returns\n        -------\n        y : Series or DataFrame if func returns a Series\n\n        See also\n        --------\n        Series.map: For element-wise operations\n\n        Examples\n        --------\n\n        Create a series with typical summer temperatures for each city.\n\n        >>> import pandas as pd\n        >>> import numpy as np\n        >>> series = pd.Series([20, 21, 12], index=['London',\n        ... 'New York','Helsinki'])\n        London      20\n        New York    21\n        Helsinki    12\n        dtype: int64\n\n        Square the values by defining a function and passing it as an\n        argument to ``apply()``.\n\n        >>> def square(x):\n        ...     return x**2\n        >>> series.apply(square)\n        London      400\n        New York    441\n        Helsinki    144\n        dtype: int64\n\n        Square the values by passing an anonymous function as an\n        argument to ``apply()``.\n\n        >>> series.apply(lambda x: x**2)\n        London      400\n        New York    441\n        Helsinki    144\n        dtype: int64\n\n        Define a custom function that needs additional positional\n        arguments and pass these additional arguments using the\n        ``args`` keyword.\n\n        >>> def subtract_custom_value(x, custom_value):\n        ...     return x-custom_value\n\n        >>> series.apply(subtract_custom_value, args=(5,))\n        London      15\n        New York    16\n        Helsinki     7\n        dtype: int64\n\n        Define a custom function that takes keyword arguments\n        and pass these arguments to ``apply``.\n\n        >>> def add_custom_values(x, **kwargs):\n        ...     for month in kwargs:\n        ...         x+=kwargs[month]\n        ...         return x\n\n        >>> series.apply(add_custom_values, june=30, july=20, august=25)\n        London      95\n        New York    96\n        Helsinki    87\n        dtype: int64\n\n        Use a function from the Numpy library.\n\n        >>> series.apply(np.log)\n        London      2.995732\n        New York    3.044522\n        Helsinki    2.484907\n        dtype: float64\n\n\n        " #NEWLINE# if ( len ( self ) == 0 ) : #NEWLINE# #INDENT# return self . _constructor ( dtype = self . dtype , index = self . index ) . __finalize__ ( self ) #NEWLINE# #UNINDENT# if ( kwds or ( args and ( not isinstance ( func , np . ufunc ) ) ) ) : #NEWLINE# #INDENT# f = ( lambda x : func ( x , * args , ** kwds ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# f = func #NEWLINE# #UNINDENT# if isinstance ( f , np . ufunc ) : #NEWLINE# #INDENT# return f ( self ) #NEWLINE# #UNINDENT# if is_extension_type ( self . dtype ) : #NEWLINE# #INDENT# mapped = self . _values . map ( f ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# values = self . asobject #NEWLINE# mapped = lib . map_infer ( values , func , convert = convert_dtype ) #NEWLINE# #UNINDENT# if ( len ( mapped ) and isinstance ( mapped [ 0 ] , Series ) ) : #NEWLINE# #INDENT# from pandas.core.frame import DataFrame #NEWLINE# return DataFrame ( mapped . tolist ( ) , index = self . index ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return self . _constructor ( mapped , index = self . index ) . __finalize__ ( self )