{"id":16966,"date":"2020-03-21T19:13:58","date_gmt":"2020-03-21T23:13:58","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/python-generate-expense-report-from-rbc-mastercard-transaction-data\/"},"modified":"2020-03-21T19:13:58","modified_gmt":"2020-03-21T23:13:58","slug":"python-generate-expense-report-from-rbc-mastercard-transaction-data","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=16966","title":{"rendered":"Python: Generate Expense Report from RBC MasterCard Transaction Data"},"content":{"rendered":"<p>Python: Generate Expense Report from RBC MasterCard Transaction Data<\/p>\n<p>For the context read the following two first<\/p>\n<p><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-read-rbc-canada-mastercard-pdf-statement-transaction-data-into-csv-file-99aa451c0016\"><\/a><\/p>\n<h2><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-read-rbc-canada-mastercard-pdf-statement-transaction-data-into-csv-file-99aa451c0016\">Python: Read RBC Canada: Mastercard PDF Statement Transaction Data into CSV file<\/a><\/h2>\n<p><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-read-rbc-canada-mastercard-pdf-statement-transaction-data-into-csv-file-99aa451c0016\"><\/a> <\/p>\n<h3><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-read-rbc-canada-mastercard-pdf-statement-transaction-data-into-csv-file-99aa451c0016\">By Sayed Ahmed<\/a><\/h3>\n<p><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-read-rbc-canada-mastercard-pdf-statement-transaction-data-into-csv-file-99aa451c0016\"><br \/>\n<\/a> <\/p>\n<h4><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-read-rbc-canada-mastercard-pdf-statement-transaction-data-into-csv-file-99aa451c0016\">medium.com<\/a><\/h4>\n<p><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-read-rbc-canada-mastercard-pdf-statement-transaction-data-into-csv-file-99aa451c0016\"><\/p>\n<p><\/a><br \/>\n<a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-merge-multiple-csv-files-into-one-to-facilitate-reporting-on-transaction-data-over-time-2e4524355d43\"><\/a><\/p>\n<h2><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-merge-multiple-csv-files-into-one-to-facilitate-reporting-on-transaction-data-over-time-2e4524355d43\">Python: Merge Multiple csv files into one to facilitate reporting on transaction data over time<\/a><\/h2>\n<p><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-merge-multiple-csv-files-into-one-to-facilitate-reporting-on-transaction-data-over-time-2e4524355d43\"><\/a> <\/p>\n<h3><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-merge-multiple-csv-files-into-one-to-facilitate-reporting-on-transaction-data-over-time-2e4524355d43\">By Sayed Ahmed<\/a><\/h3>\n<p><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-merge-multiple-csv-files-into-one-to-facilitate-reporting-on-transaction-data-over-time-2e4524355d43\"><br \/>\n<\/a> <\/p>\n<h4><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-merge-multiple-csv-files-into-one-to-facilitate-reporting-on-transaction-data-over-time-2e4524355d43\">medium.com<\/a><\/h4>\n<p><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\/python-merge-multiple-csv-files-into-one-to-facilitate-reporting-on-transaction-data-over-time-2e4524355d43\"><\/p>\n<p><\/a><\/p>\n<p>After, you have created the merged i.e. combined csv file, you might want to create reports for your purpose. For example, you can calculate how much was spent on Amazon.ca. The code example will show similar how much was spent on Amazon.ca.<\/p>\n<p>Just by changing the variab;e<\/p>\n<pre>spend_calculation_for = \u2018<a href=\"http:\/\/AMAZON.CA\">AMAZON.CA<\/a>\u2019;<\/pre>\n<p> you will be able to calculate how much was spent on other places such as BestBuy, Ebay or similar. The code is case sensitive; Hence, you need to provide the value exactly for the above mentioned variable.<\/p>\n<p>Statements such as dollar, no_dol_sign_dollar, you might want to use print for them. This code was written in Jupyter Notebook and then was exported to .py file.<\/p>\n<pre>#!\/usr\/bin\/env python\n# coding: utf-8# In[1]:import os;\nimport glob;\nimport pandas as pd;\ndata_folder = \u2018.\/\u2019;\nos.chdir(data_folder);# In[2]:Spend_calculation_for = \u2018<a href=\"http:\/\/AMAZON.CA\">AMAZON.CA<\/a>\u2019;# In[3]:df = pd.read_csv(\u2018to_process_rbc_mastercard_data_combined.csv\u2019)\ndf.head(3)# In[4]:transactions = df[ df[\u20182\u2019].str.contains(Spend_calculation_for) ]# In[5]:dollar = transactions[0:50][\u20183\u2019]\ndollar = sorted(dollar)\ndollar# In[6]:no_dol_sign_dollar = [x.strip(\u201c$\u201d) for x in dollar]\nno_dol_sign_dollar# In[7]:no_dol_sign_dollar = [float(x.replace(\u201c-$\u201d, \u2018-\u2019)) for x in no_dol_sign_dollar]\nno_dol_sign_dollar# In[8]:import math\ntotal_spent = sum(no_dol_sign_dollar)\n#sum = sum + [ float(x[1:]) for x in aliexpress_dollar ]\ntotal_spent# In[9]:# just spent without refund\npos_no_dol_sign_dollar = [ x if x &gt; 0 else 0 for x in no_dol_sign_dollar]\npos_no_dol_sign_dollar[0:10]# In[10]:spent = sum(pos_no_dol_sign_dollar)\nspent# In[11]:# just spent without refund\nneg_no_dol_sign_dollar = [ x if x &lt; 0 else 0 for x in no_dol_sign_dollar]\n#if (len(neg_no_dol_sign_aliexpress_dollar)) &gt; 0:\n# neg_no_dol_sign_aliexpress_dollar[-1], neg_no_dol_sign_aliexpress_dollar[-2], neg_no_dol_sign_aliexpress_dollar[-3]\nneg_no_dol_sign_dollar# In[12]:got_refund = sum(neg_no_dol_sign_dollar);\ngot_refund# In[14]:total_spent = spent \u2014 abs(got_refund);\ntotal_spent# In[ ]:<\/pre>\n<p> <em><\/em><br \/>\n<em><strong>***<\/strong><\/em><br \/>\n<em><strong>Note: Older short-notes from this site are posted on Medium: <\/strong><\/em><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\">https:\/\/medium.com\/@SayedAhmedCanada<\/a><\/p>\n<p>*** . *** *** . *** . *** . ***<br \/>\n<em><strong>Sayed Ahmed<\/strong><br \/>\n<\/em><br \/>\n<em><strong>BSc. Eng. in Comp. Sc. &amp; Eng. (BUET)<\/strong><\/em><br \/>\n<em><strong>MSc. in Comp. Sc. (U of Manitoba, Canada)<\/strong><\/em><br \/>\n<em><strong>MSc. in Data Science and Analytics (Ryerson University, Canada)<\/strong><\/em><br \/>\n<em><strong>Linkedin<\/strong>: <a href=\"https:\/\/ca.linkedin.com\/in\/sayedjustetc\">https:\/\/ca.linkedin.com\/in\/sayedjustetc<\/a><br \/>\n<\/em><\/p>\n<p><em><strong>Blog<\/strong>: <a href=\"http:\/\/bangla.salearningschool.com\/\">http:\/\/Bangla.SaLearningSchool.com<\/a>, <a href=\"http:\/\/sitestree.com\">http:\/\/SitesTree.com<\/a><\/em><br \/>\n<em><strong>Training Courses: <\/strong><a href=\"http:\/\/training.SitesTree.com\">http:\/\/Training.SitesTree.com<\/a> <\/em><\/p>\n<p><em><strong>Facebook Groups\/Forums to discuss (Q &amp; A): <\/strong><\/em><br \/>\n<a href=\"https:\/\/www.facebook.com\/banglasalearningschool\">https:\/\/www.facebook.com\/banglasalearningschool<\/a><br \/>\n<a href=\"https:\/\/www.facebook.com\/justetcsocial\">https:\/\/www.facebook.com\/justetcsocial<\/a><\/p>\n<p><em>Get access to courses on Big Data, Data Science, AI, Cloud, Linux, System Admin, Web Development and Misc. related. Also, create your own course to sell to others. <\/em><a href=\"http:\/\/sitestree.com\/training\/\">http:\/\/sitestree.com\/training\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python: Generate Expense Report from RBC MasterCard Transaction Data For the context read the following two first Python: Read RBC Canada: Mastercard PDF Statement Transaction Data into CSV file By Sayed Ahmed medium.com Python: Merge Multiple csv files into one to facilitate reporting on transaction data over time By Sayed Ahmed medium.com After, you have &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=16966\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[182],"tags":[],"class_list":["post-16966","post","type-post","status-publish","format-standard","hentry","category---blog","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":16968,"url":"http:\/\/bangla.sitestree.com\/?p=16968","url_meta":{"origin":16966,"position":0},"title":"Python: Read Amex (American Express) Canada: Mastercard PDF Statement Transaction Data into CSV file","author":"Sayed","date":"March 26, 2020","format":false,"excerpt":"Python: Read Amex (American Express) Canada: PDF Statement Transaction Data into CSV file By Sayed Ahmed In general, you will get CSV files from your Amex card; However, sometimes you need to download in every 3 or 6 months. Otherwise, you might only get\/request pdf files for transactions (depends on\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16962,"url":"http:\/\/bangla.sitestree.com\/?p=16962","url_meta":{"origin":16966,"position":1},"title":"Python: Read RBC Canada: Mastercard Statement Data into CSV file","author":"Sayed","date":"March 19, 2020","format":false,"excerpt":"Sure, you can use tools such as Adobe Acrobat to convert PDF statements to csv\/xls files. This is a simple approach that you might be able to use when you do not have access to any such tools. How can this help? If you were trying to calculate based on\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16964,"url":"http:\/\/bangla.sitestree.com\/?p=16964","url_meta":{"origin":16966,"position":2},"title":"Python: Merge Multiple csv files into one to facilitate reporting on transaction data over time","author":"Sayed","date":"March 21, 2020","format":false,"excerpt":"Python: Merge Multiple csv files into one to facilitate reporting on transaction data over time By Sayed Ahmed Merge multiple transaction files into one. This is an extension to the article: Python: Read RBC Canada: Mastercard PDF Statement Transaction Data into CSV file By Sayed Ahmedmedium.com The Code for Merging\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16965,"url":"http:\/\/bangla.sitestree.com\/?p=16965","url_meta":{"origin":16966,"position":3},"title":"Python: Merge Multiple csv files into one to facilitate reporting on transaction data over time","author":"Sayed","date":"March 21, 2020","format":false,"excerpt":"Python: Merge Multiple csv files into one to facilitate reporting on transaction data over time","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":72698,"url":"http:\/\/bangla.sitestree.com\/?p=72698","url_meta":{"origin":16966,"position":4},"title":"10 new jobs &#8211; dotnet in various locations","author":"Sayed","date":"February 5, 2022","format":false,"excerpt":"Full Stack Developer Melcher Studios Regina, SK TBD Systems Analyst YWI Alliance Richmond Hill, ON $41.00 hourly Full time Software Developer BRP Montr\u00e9al, QC N\/A Software Developer Home Depot of Canada Inc. Toronto, ON N\/A Web Developer Premier Tech Montr\u00e9al, QC N\/A Programmer, Web NTT DATA Toronto, ON N\/A Java\u2026","rel":"","context":"In &quot;Jobs in Canada and USA&quot;","block_context":{"text":"Jobs in Canada and USA","link":"http:\/\/bangla.sitestree.com\/?cat=1953"},"img":{"alt_text":"SaskJobs","src":"https:\/\/i0.wp.com\/www.jobbank.gc.ca\/themes-jb\/images\/icons\/jobsource\/list\/jobsource-6-icon.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":23136,"url":"http:\/\/bangla.sitestree.com\/?p=23136","url_meta":{"origin":16966,"position":5},"title":"Where to open RESP account? #Root #By Sayed Ahmed","author":"Author-Check- Article-or-Video","date":"March 25, 2021","format":false,"excerpt":"Where to open RESP account? http:\/\/www.esdc.gc.ca\/en\/student_loans\/resp\/promoters_list.page#A You can also check if the institute offers CLB - Canada Learning Bond, ACESG -Additional Canada Education Savings Grant, Everybody has CESG \u00a0 Questrade Offers all RBC Direct Investing Offers all CIBC some Schemes offer all RBC Target Education plans offer all \u00a0 if\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/16966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16966"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/16966\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16966"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}