Python | Pandas Series.pow()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Series.pow() is a series mathematical operation method. This is used to put each element of passed series as exponential power of caller series and returned the results. For this, index of both the series has to be same otherwise error is returned.
Syntax: Series.pow(other, =None, fill_value=None, axis=0)
other: Other series or list type to be put as exponential power to the caller series
level: Value to be replaced by NaN in series/list before operation
fill_value: Integer value of level in case of multi index
Return : Value of caller series with other series as its exponential power
In this example, two Series are created using Pandas .Series() method. None of the series is having null values. The second series is directly passed as other parameter to return the values after operation.
As shown in the output, the returned values are equal to first series with second series as its exponential power.
0 1 1 8 2 25 3 6 4 27 5 16 dtype: int64
Example #2: Handling Null values
In this example, NaN values are also put in the series using numpy.nan method. After that 2 is passed to fill_value parameter to replace null values with 2.
As shown in the output, all NaN values were replaced by 2 before the operation and result was returned without any Null value in it.
0 1.0 1 4.0 2 125.0 3 36.0 4 9.0 5 2.0 6 64.0 7 4.0 dtype: float64
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course