Python | Pandas Series.pow ()



Pandas Series.pow() — method of mathematical operation series. This is used to mark each element of the missing series as the exponential power of the caller series and return the results. For this, the index of both series must be the same, otherwise an error is returned.

Syntax: Series.pow (other, = None, fill_value = None, axis = 0 )

Parameters:
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

Example # 1:
This example has two series are created using the Pandas .Series () method. None of the rows have zero values. The second series is directly passed as another parameter to return values ​​after the operation.

# pandas module import

import pandas as pd

 
# create the first episode

first = [ 1 , 2 , 5 , 6 , 3 , 4 ]

 
# create second series

second = [ 5 , 3 , 2 , 1 , 3 , 2 ]

 
# create series

first = pd.Series (first)

 
# create series

second = pd.Series (second)

 
# .pow () call

result < code class = "keyword"> = first. pow (second)

 
# display
result

Output:
As shown in the output, the returned values ​​are equal to the first run with the second run as the exponential.

 0 1 1 8 2 25 3 6 4 27 5 16 dtype: int64  

Example # 2: Handling Null Values ​​

This example also puts NaN values ​​in a row using the numpy.nan method. After that, 2 is passed to the fill_value parameter to replace the zero values ​​with 2.

# pandas module import

import pandas as pd

 
# numpy module import

import numpy as np

 
# create the first episode

first = [ 1 , 2 , 5 , 6 , 3 , np.nan, < / code> 4 , np.nan]

 
# create second episode

second = [ 5 , np.nan, 3 , 2 , np.nan , 1 , 3 , 2 ]

  
# create series

first = pd.Series (first)

 
# creating the series

second = pd.Series (second)

 
# value for null replacement

null_replacement = 2

 
# call .pow ()

result = first . pow (second, fill_value = null_replacement)

 
# display
result

Output:
As shown in the output, all NaN values ​​were replaced with 2s before the operation, and the result was returned without a Null value.

 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