I have a pandas dataframe with two columns, PaymentID and WasDenied. I want to add that WasDenied column to my SQL table “Payments” by merging on the PaymentID column. Is there any way to do that?
I’m familiar with pandas .to_sql()
but I don’t think the replace or append options in the if_exists
parameter will help because I’m not looking to append or replace, I’m looking to merge/join, although I could be wrong.
Payment Table in SQL:
PaymentID | Payment Type | Payment Amount |
---|---|---|
123 | Credit Card | $100.00 |
456 | Cash | $25.50 |
456 | Cash | $25.50 |
789 | Bank Transfer | $500.75 |
101 | Debit Card | $32.14 |
101 | Debit Card | $35.20 |
WasDenied table in Pandas:
PaymentID | WasDenied |
---|---|
123 | True |
456 | False |
789 | False |
101 | True |
df = pd.DataFrame([[123, True],[456, False], [789, False], [101, True]], columns=['PaymentID', 'WasDenial'])
df