Created
September 8, 2023 16:50
-
-
Save Softwaretrain/9900cfde91fb8147d021333b3bfd2bb9 to your computer and use it in GitHub Desktop.
Reconciliation with Python in Excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # خواندن جداول ورودی | |
| bank = xl("Bank[#All]", headers=True) | |
| dafater = xl("Dafater[#All]", headers=True) | |
| # ایجاد ستون جدید با ترکیب مبلغ و تاریخ و شماره گذاری در صورت تکراری بودن | |
| bank['ترکیب'] = bank['مبلغ'].astype(str) + '-' + bank['تاریخ'].astype(str) + '-' + bank.groupby(['مبلغ', 'تاریخ']).cumcount().add(1).astype(str) | |
| dafater['ترکیب'] = dafater['مبلغ'].astype(str) + '-' + dafater['تاریخ'].astype(str) + '-' + dafater.groupby(['مبلغ', 'تاریخ']).cumcount().add(1).astype(str) | |
| # مقایسه دو فایل بر اساس ستون ترکیب | |
| result_bank = bank[~bank['ترکیب'].isin(dafater['ترکیب'])] | |
| result_dafater = dafater[~dafater['ترکیب'].isin(bank['ترکیب'])] | |
| # افزودن ستون منبع به نتایج مربوط به هر فایل | |
| result_bank['منبع'] = 'بانک' | |
| result_dafater['منبع'] = 'دفاتر' | |
| # ترکیب دو نتیجه | |
| result = pd.concat([result_bank, result_dafater], ignore_index=True) | |
| # حذف ستون ترکیب | |
| result = result.drop(columns=['ترکیب']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment