Find Exponential of a column in Pandas-Python
Last Updated :
02 Jul, 2021
Let’s see how to find Exponential of a column in Pandas Dataframe. First, let’s create a Dataframe:
Python3
import pandas as pd
import numpy as np
values = [ [ 'Rohan' , 5 , 50.59 ], [ 'Elvish' , 2 , 90.57 ],
[ 'Deepak' , 10 , 98.51 ], [ 'Soni' , 4 , 40.24 ],
[ 'Radhika' , 1 , 99.05 ], [ 'Vansh' , 15 , 85.56 ] ]
df = pd.DataFrame(values, columns = [ 'Name' ,
'University_Rank' ,
'University_Marks' ])
df
|
Output:
The exponential of any column is found out by using numpy.exp() function. This function calculates the exponential of the input array/Series.
Syntax: numpy.exp(array, out = None, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None)
Return: An array with exponential of all elements of input array/Series.
Example 1: Finding exponential of the single column (integer values).
Python3
import pandas as pd
import numpy as np
values = [ [ 'Rohan' , 5 , 50.59 ], [ 'Elvish' , 2 , 90.57 ],
[ 'Deepak' , 10 , 98.51 ], [ 'Soni' , 4 , 40.24 ],
[ 'Radhika' , 1 , 99.05 ], [ 'Vansh' , 15 , 85.56 ] ]
df = pd.DataFrame(values, columns = [ 'Name' ,
'University_Rank' ,
'University_Marks' ])
df[ 'exp_value' ] = np.exp(df[ 'University_Rank' ])
df
|
Output:
Example 2: Finding exponential of the single column (Float values).
Python3
import pandas as pd
import numpy as np
values = [ [ 'Rohan' , 5 , 50.59 ], [ 'Elvish' , 2 , 90.57 ],
[ 'Deepak' , 10 , 98.51 ], [ 'Soni' , 4 , 40.24 ],
[ 'Radhika' , 1 , 99.05 ], [ 'Vansh' , 15 , 85.56 ] ]
df = pd.DataFrame(values, columns = [ 'Name' ,
'University_Rank' ,
'University_Marks' ])
df[ 'exp_value' ] = np.exp(df[ 'University_Marks' ])
df
|
Output:
Share your thoughts in the comments
Please Login to comment...