Let’s see how to find Exponential of a column in Pandas Dataframe. First, let’s create a Dataframe:
Python3
# importing pandas and # numpy libraries import pandas as pd import numpy as np # creating and initializing a list 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 ] ] # creating a pandas dataframe df = pd.DataFrame(values, columns = [ 'Name' , 'University_Rank' , 'University_Marks' ]) # displaying the data frame 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
# importing pandas and # numpy libraries import pandas as pd import numpy as np # creating and initializing a list 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 ] ] # creating a pandas dataframe df = pd.DataFrame(values, columns = [ 'Name' , 'University_Rank' , 'University_Marks' ]) # finding the exponential value # of column using np.exp() function df[ 'exp_value' ] = np.exp(df[ 'University_Rank' ]) # displaying the data frame df |
Output:
Example 2: Finding exponential of the single column (Float values).
Python3
# importing pandas and # numpy libraries import pandas as pd import numpy as np # creating and initializing a list 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 ] ] # creating a pandas dataframe df = pd.DataFrame(values, columns = [ 'Name' , 'University_Rank' , 'University_Marks' ]) # finding the exponential value # of column using np.exp() function df[ 'exp_value' ] = np.exp(df[ 'University_Marks' ]) # displaying the data frame df |
Output: