To create a third dataframe that shows the differences in values between the two original dataframes, you can follow these steps:
Merge the two dataframes together using a common key column. If the two dataframes have a column with the same name and data type, you can use that column as the key column. For example:
merged_df = pd.merge(df1, df2, on='Product Code')
This will create a new dataframe merged_df that contains all the columns from both df1 and df2.
Calculate the differences between the columns that you are interested in. For example, if you want to calculate the difference between the "Quantity" column in df1 and df2, you can subtract the "Quantity" column in df2 from the "Quantity" column in df1.
merged_df['Quantity Diff'] = merged_df['Quantity_x'] - merged_df['Quantity_y']
This will create a new column "Quantity Diff" in merged_df that contains the differences between the "Quantity" columns in df1 and df2.
Repeat step 2 for the other columns that you are interested in. For example:
merged_df['Price Diff'] = merged_df['Price_x'] - merged_df['Price_y']
merged_df['Local Value Diff'] = merged_df['Local Value_x'] - merged_df['Local Value_y']
merged_df['Local Exposure Diff'] = merged_df['Local Exposure_x'] - merged_df['Local Exposure_y']
This will create new columns in merged_df that contain the differences between the corresponding columns in df1 and df2.
Create a new dataframe that contains only the columns that you are interested in. For example:
diff_df = merged_df[['Product Code', 'Quantity Diff', 'Price Diff', 'Local Value Diff', 'Local Exposure Diff']]
This will create a new dataframe diff_df that contains only the columns "Product Code", "Quantity Diff", "Price Diff", "Local Value Diff", and "Local Exposure Diff".
Optionally, you can sort the dataframe by the "Product Code" column to make it easier to read. For example:
diff_df = diff_df.sort_values('Product Code')
This will sort the rows in diff_df by the "Product Code" column in ascending order.