VOOZH about

URL: https://www.geeksforgeeks.org/python/difference-of-two-columns-in-pandas-dataframe/

⇱ Difference of two columns in Pandas dataframe - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Difference of two columns in Pandas dataframe

Last Updated : 3 Oct, 2025

In Python, the difference between two columns in a Pandas DataFrame can be calculated using multiple methods. Here, we will discuss two simple approaches:

  1. Using "-" difference/subtract operator
  2. Using sub() method.

Method 1: Using the "-" Operator

You can directly subtract one column from another using the "-" operator to create a new column.


Output
Difference of score1 and score2 :
 Name score1 score2 Score_diff
0 George 62 45 17
1 Andrea 47 78 -31
2 micheal 55 44 11
3 magg...

Method 2: Using the sub() Method

Pandas provides a built-in method sub() to subtract one column from another. It is particularly useful when performing element-wise subtraction with alignment along a particular axis.


Output
Difference of score1 and score2 :
 Name score1 score2 Score_diff
0 George 62 45 17
1 Andrea 47 78 -31
2 micheal 55 44 11
3 magg...

Related Articles:

Comment