Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
920 B
1
Indexable
Never
import pandas as pd

def compare_excel_sheets(file1_path, file2_path, output_path):
    # Read the Excel sheets
    df1 = pd.read_excel(file1_path)
    df2 = pd.read_excel(file2_path)

    # Find the column index for "Software Features" in both DataFrames
    column_name = "Software Features"
    col_index1 = df1.columns.get_loc(column_name)
    col_index2 = df2.columns.get_loc(column_name)

    # Compare values row by row
    df1[column_name] = df1.iloc[:, col_index1].astype(str)
    df2[column_name] = df2.iloc[:, col_index2].astype(str)
    df1['Different'] = df1[column_name] != df2[column_name]

    # Optionally, save the modified Excel sheet
    if output_path:
        df1.to_excel(output_path, index=False)

    return df1

# Example usage
file1_path = "file1.xlsx"
file2_path = "file2.xlsx"
output_path = "output.xlsx"
compare_excel_sheets(file1_path, file2_path, output_path)
Leave a Comment