import pandas as pd # Read the Excel files df1 = pd.read_excel('Downloads/UUID with Farmonaut.xlsx') df2 = pd.read_excel('Downloads/All Fields ipRHhCOFIDV2pxgg7Nfz1ufZBmV2 (1).xlsx') # Initialize an empty list to store the matching IDs matching_ids = [] # Iterate through the rows of excel sheet 2 for index, row in df2.iterrows(): # Get the value from column C and split it by comma description_values = row['C'].split(',') # Get the first element from the split values first_element = description_values[0].strip() # Compare the first element with the values in column D of excel sheet 1 matching_row = df1[df1['D'] == first_element] if not matching_row.empty: # If a match is found, add the value of column B from excel sheet 1 to the list matching_ids.append(matching_row['B'].values[0]) # Save the resulting array to a new Excel sheet result_df = pd.DataFrame(matching_ids, columns=['Matching IDs']) result_df.to_excel('matching_ids.xlsx', index=False)