Raised power of column in pandas python – power () function

Raised power of column in pandas python is carried out using power() function of numpy. Let’s see how to

  • Get the Raised power of a value in column of pandas python.

With an example. First let’s create a dataframe

import pandas as pd
import numpy as np

#Create a DataFrame
df1 = {
     'Name':['George','Andrea','micheal','maggie','Ravi','Xien','Jalpa'],
   'University_Rank':[6,47,21,74,32,77,8]}

df1 = pd.DataFrame(df1,columns=['Name','University_Rank'])
print(df1)

df1 will be

Raised power of column in pandas python 1

 

Raised power of column in pandas – (power of 2)

Raised power of the column (University_Rank) is computed using power() function and stored in a new column namely “Raised_power_value”  as shown below.


df1['Raised_power_value'] = np.power((df1['University_Rank']),2)
print(df1)

power raised to 2 of a column is calculated and populated, so the resultant dataframe will be

Raised power of column in pandas python 2

 

Raised power of column in pandas – (power of 3) 

Raised power of 3 to the column (University_Rank) is computed using power() function and stored in a new column namely “Raised_power_value”  as shown below


df1['Raised_power_value'] = np.power((df1['University_Rank']),3)
print(df1)	

power raised to 3 of a column is calculated and populated, so the resultant dataframe will be

Raised power of column in pandas python 3

 

Raised power of column in pandas python - power () function prev                                                                                                                Raised power of column in pandas python - power () function