Square root of the column in pandas python

Getting the square root of the column in pandas python can be done in two ways using sqrt() function. Let’s see how to

  •     Get the square root of the column in pandas python

With examples

First let’s create a dataframe


import pandas as pd
import numpy as np

df1 = {
    'State':['Arizona AZ','Georgia GG','Newyork NY','Indiana IN','Florida FL'],
   'Score':[4,47,55,74,31]}

df1 = pd.DataFrame(df1,columns=['State','Score'])
print(df1)

df1 will be

Square root of the column in pandas python 1

 

Square root of the column in pandas – Method 1:

Simply get the square root of the column and store in other column as shown below


df1['Score_Squareroot']=df1['Score']**(1/2)
print(df1)

So the resultant dataframe will be

Square root of the column in pandas python 2

 

Square root of the column in pandas – Method 2:

Square root of the column using sqrt() function and store it in other column as shown below


df1['Score_squareroot']=np.sqrt((df1['Score']))
print(df1)

So the resultant dataframe will be

Square root of the column in pandas python 3

 

p Square root of the column in pandas python                                                                                                                n Square root of the column in pandas python