Reconciling Transactions with Python
1234567891011121314151617181920212223242526import pandas as pd # Sample bank transactions bank_data = { "Date": ["2024-06-01", "2024-06-02", "2024-06-03"], "Description": ["Deposit", "Withdrawal", "Payment"], "Amount": [1000, -200, -150] } bank_df = pd.DataFrame(bank_data) # Sample ledger transactions ledger_data = { "Date": ["2024-06-01", "2024-06-02", "2024-06-04"], "Description": ["Deposit", "Withdrawal", "Fee"], "Amount": [1000, -200, -50] } ledger_df = pd.DataFrame(ledger_data) # Merge on all columns to find exact matches merged = pd.merge(bank_df, ledger_df, how="outer", indicator=True) # Find transactions not matched in both datasets unmatched = merged[merged["_merge"] != "both"] print("Unmatched transactions:") print(unmatched)
1234567891011121314151617181920import pandas as pd # Example datasets bank = pd.DataFrame({ "Date": ["2024-06-01", "2024-06-02"], "Amount": [500, -100] }) ledger = pd.DataFrame({ "Date": ["2024-06-01", "2024-06-03"], "Amount": [500, -50] }) # Merge and flag discrepancies merged = pd.merge(bank, ledger, on=["Date", "Amount"], how="outer", indicator=True) discrepancies = merged[merged["_merge"] != "both"] # Report discrepancies for idx, row in discrepancies.iterrows(): source = "Bank" if row["_merge"] == "left_only" else "Ledger" print(f"Discrepancy found in {source}: Date {row['Date']}, Amount {row['Amount']}")
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 3
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Fantastiskt!
Completion betyg förbättrat till 7.14
Reconciling Transactions with Python
Svep för att visa menyn
1234567891011121314151617181920212223242526import pandas as pd # Sample bank transactions bank_data = { "Date": ["2024-06-01", "2024-06-02", "2024-06-03"], "Description": ["Deposit", "Withdrawal", "Payment"], "Amount": [1000, -200, -150] } bank_df = pd.DataFrame(bank_data) # Sample ledger transactions ledger_data = { "Date": ["2024-06-01", "2024-06-02", "2024-06-04"], "Description": ["Deposit", "Withdrawal", "Fee"], "Amount": [1000, -200, -50] } ledger_df = pd.DataFrame(ledger_data) # Merge on all columns to find exact matches merged = pd.merge(bank_df, ledger_df, how="outer", indicator=True) # Find transactions not matched in both datasets unmatched = merged[merged["_merge"] != "both"] print("Unmatched transactions:") print(unmatched)
1234567891011121314151617181920import pandas as pd # Example datasets bank = pd.DataFrame({ "Date": ["2024-06-01", "2024-06-02"], "Amount": [500, -100] }) ledger = pd.DataFrame({ "Date": ["2024-06-01", "2024-06-03"], "Amount": [500, -50] }) # Merge and flag discrepancies merged = pd.merge(bank, ledger, on=["Date", "Amount"], how="outer", indicator=True) discrepancies = merged[merged["_merge"] != "both"] # Report discrepancies for idx, row in discrepancies.iterrows(): source = "Bank" if row["_merge"] == "left_only" else "Ledger" print(f"Discrepancy found in {source}: Date {row['Date']}, Amount {row['Amount']}")
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 3