Untitled
unknown
plain_text
a year ago
1.1 kB
1
Indexable
Never
# ... (existing code above) # Assuming 'your_primary_key_column' is the primary key column name merged_df = pd.merge(df, target_df, on='your_primary_key_column', suffixes=('_source', '_target'), how='inner') # Iterate through merged DataFrame to compare columns and generate update queries for index, row in merged_df.iterrows(): primary_key_value = row['your_primary_key_column'] # Replace with the actual column name # Initialize a list to store column updates column_updates = [] # Compare columns for changes for column_name in df.columns: source_value = row[column_name + '_source'] target_value = row[column_name + '_target'] if source_value != target_value: column_updates.append(f"{column_name}='{source_value}'") # Generate and execute an SQL update statement if there are column updates if column_updates: update_query = f"UPDATE {schema_ext}.your_table SET {', '.join(column_updates)} WHERE your_primary_key_column='{primary_key_value}'" connection_ext.execute(update_query) # ... (continue with your existing code below)