Using Python to find the difference between two columns of numbers from an excel file
import pandas as pd
Read the Excel file into a pandas DataFrame
df = pd.read_excel('file.xlsx')
Find the difference between the two columns
df['difference'] = df['column1'] - df['column2']
Print the resulting DataFrame
print(df)
I have an excel file that I have imported into Python using pandas and it has two columns, purchase price and sales price. They are both number values. I want to use python to automatically do the math for me to find the difference between the two, in this case I want it to be Sales Price minus Purchase Price. Is it possible to write a script for this? Thanks in advance for any help.