Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python dataframe calculate difference between columns

import pandas as pd
  
# Create a DataFrame
df1 = { 'Name':['George','Andrea','micheal',
                'maggie','Ravi','Xien','Jalpa'],
        'score1':[62,47,55,74,32,77,86],
        'score2':[45,78,44,89,66,49,72]}
  
df1 = pd.DataFrame(df1,columns= ['Name','score1','score2'])
  
print("Given Dataframe :
", df1)
  
# getting Difference
df1['Score_diff'] = df1['score1'] - df1['score2']
print("
Difference of score1 and score2 :
", df1)
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #python #dataframe #calculate #difference #columns
ADD COMMENT
Topic
Name
7+6 =