Get the absolute value of column in pandas python

abs is the function used to get the absolute value of column in pandas python. Let’s see how to

  • Get the absolute value of column in pandas python

Let’s first create the dataframe.

import pandas as pd
import numpy as np

#Create a DataFrame
df1 = {
    'Subject':['semester1','semester2','semester3','semester4','semester1',
               'semester2','semester3'],
   'Score':[-62,47,-55,-74,31,77,-85]}
df1 = pd.DataFrame(df1,columns=['Subject','Score'])
print(df1)

So the resultant dataframe will be

Get the absolute value of column in pandas python 1

 

Let’s get the absolute value of a column in pandas dataframe with abs function as shown below


df1['Absolute_Score']= abs(df1['Score'])
print(df1)

So the result will be

Get the absolute value of column in pandas python 2

Get the absolute value of column in pandas python                                                                                                                Get the absolute value of column in pandas python n