{"id":16962,"date":"2020-03-19T20:53:29","date_gmt":"2020-03-20T00:53:29","guid":{"rendered":"https:\/\/bangla.salearningschool.com\/recent-posts\/python-read-rbc-canada-mastercard-statement-data-into-csv-file\/"},"modified":"2020-03-19T20:53:29","modified_gmt":"2020-03-20T00:53:29","slug":"python-read-rbc-canada-mastercard-statement-data-into-csv-file","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=16962","title":{"rendered":"Python: Read RBC Canada: Mastercard Statement Data into CSV file"},"content":{"rendered":"<p>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.<\/p>\n<p>How can this help? If you were trying to calculate based on the transactions. One application can be calculating your business or personal expenses. Also, if you are writing a tax or financial software, similar can be useful. For sure, tools and programming languages are available to read PDF files directly than the approach I mentioned here.<\/p>\n<p><strong>Steps:<\/strong><\/p>\n<p>Download the statement.<br \/>\nCopy the text (only the transactions) into a text file<br \/>\nThe use the code provided here or similar to read the text file and create a CSV file<br \/>\nYou can write another Python code to merge multiple csv files<br \/>\nUsing the combined CSV file, you can calculate your yearly categorized expenses or similar : for example<\/p>\n<p><strong>Sample Transaction Data<\/strong><br \/>\n&#8216;DEC 21 DEC 24 PAYMENT &#8211; THANK YOU \/ PAIEMENT &#8211; MERCI\\n75105398358619984366202\\n-$60.00\\nJAN 10 JAN 10 PAYMENT &#8211; THANK YOU \/ PAIEMENT &#8211; MERCI\\n75105399010619980541202\\n-$21.82\\nJAN 10 JAN 10 PURCHASE INTEREST 19.99% \\n12312312312\\n-$0.82\\n\\n\\nDEC 10 DEC 12 PRESTO VIC PARK RELOAD EAST YORK ON\\n55134428345800179063337\\n$10.25\\nDEC 13 DEC 14 TIM HORTONS 0670 QTH TORONTO ON\\n55419218347200311042837\\n$1.80\\n<\/p>\n<p><strong>Note:<\/strong><br \/>\nAssume that each transaction spans into three lines when you copy from a pdf file to a text file. The lines with interest charges might span into only one line. You can convert that into 3 lines before executing the code on it.<\/p>\n<p>DEC 21 DEC 24 PAYMENT &#8211; THANK YOU \/ PAIEMENT &#8211; MERCI<br \/>\n75105398358619984366202<br \/>\n-$60.00<br \/>\nJAN 10 JAN 10 PAYMENT &#8211; THANK YOU \/ PAIEMENT &#8211; MERCI<br \/>\n75105399010619980541202<br \/>\n-$21.82<br \/>\nJAN 10 JAN 10 PURCHASE INTEREST 19.99%<br \/>\n12312312312<br \/>\n-$0.82<\/p>\n<p><strong>The Code:<\/strong><br \/>\n#!\/usr\/bin\/env python<br \/>\n# coding: utf-8<\/p>\n<p># In[5]:<\/p>\n<p>file = open(&#8216;dec2018-jan2019.txt&#8217;,&#8217;r&#8217;);<\/p>\n<p>import os.path<br \/>\nimport re<\/p>\n<p># open the file for reading<br \/>\npath = &#8216;dec2018-jan2019.txt&#8217;<br \/>\nif os.path.exists(path):<br \/>\n# print(&#8216;debug: exists&#8217;)<br \/>\nfile = open(&#8216;dec2018-jan2019.txt&#8217;,&#8217;r&#8217;)<br \/>\nelse:<br \/>\nprint(&#8216;Fatal error: file does not exist&#8217;)<br \/>\nexit(1)<\/p>\n<p># In[6]:<\/p>\n<p>fileContent = file.read()<br \/>\nfileContent<\/p>\n<p># In[ ]:<\/p>\n<p>#f = open(&quot;dec2018-jan2019.out.txt&quot;, &quot;a&quot;);<br \/>\n#f.write(&quot;Now the file has more content!&quot;)<br \/>\n#f.close()<\/p>\n<p># In[3]:<\/p>\n<p>one_line = &#8221;;<br \/>\ncount = 0;<br \/>\nf = open(&quot;dec2018-jan2019.out.txt.csv&quot;, &quot;a&quot;);<br \/>\nfile = open(&#8216;dec2018-jan2019.txt&#8217;,&#8217;r&#8217;)<br \/>\nfor line in file:<br \/>\n#print(line);<br \/>\nline = line.rstrip(&quot;\\n&quot;);<br \/>\nif line !=&#8221;:<br \/>\ncount = count + 1;<\/p>\n<p>if (count % 3 == 1):<br \/>\nline = line[0:6] + &quot;,&quot; + line[6:13] + &quot;,&quot; + line[13:];<\/p>\n<p>if (count % 3 == 2):<br \/>\nline = line + &quot;,&quot; ;<\/p>\n<p>if (count % 3 == 0):<br \/>\n#print(line[0]);<br \/>\nif line[0] == &#8216;-&#8216;:<br \/>\nline = line[1:];<br \/>\nif (line[0] != &#8216;$&#8217; ):<br \/>\nprint(&#8216;Warning possible mistake&#8217;)<\/p>\n<p>#print(count);<br \/>\none_line = one_line + line;<\/p>\n<p>if (count % 3 == 0):<br \/>\none_line = one_line + &quot;\\r\\n&quot;;<br \/>\nprint(one_line);<br \/>\nf.write(one_line);<br \/>\none_line = &#8221;;<\/p>\n<p>#print(&#8216;&#8211;&#8216;);<\/p>\n<p>f.close();<\/p>\n<p># In[ ]:<\/p>\n<p>*** ***. ***<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>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 the transactions. One application can &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=16962\">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-16962","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":16962,"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":16964,"url":"http:\/\/bangla.sitestree.com\/?p=16964","url_meta":{"origin":16962,"position":1},"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":16966,"url":"http:\/\/bangla.sitestree.com\/?p=16966","url_meta":{"origin":16962,"position":2},"title":"Python: Generate Expense Report from RBC MasterCard Transaction Data","author":"Sayed","date":"March 21, 2020","format":false,"excerpt":"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\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":17001,"url":"http:\/\/bangla.sitestree.com\/?p=17001","url_meta":{"origin":16962,"position":3},"title":"Python: Ecommerce: Part\u200a\u2014\u200a1: Merge Multiple Supplier Data Files into One File","author":"Sayed","date":"April 18, 2020","format":false,"excerpt":"Python: Ecommerce: Part\u200a\u2014\u200a1: Merge Multiple Supplier Data Files into One File Section: Merge multiple Supplier Data Files All code in one block #!\/usr\/bin\/env python # coding: utf-8 # # Section: Merge multiple Supplier Data Files # # In[1]: # if there is a need to merge multiple files \u2014 use\u2026","rel":"","context":"In &quot;Build Ecommerce Software&quot;","block_context":{"text":"Build Ecommerce Software","link":"http:\/\/bangla.sitestree.com\/?cat=1912"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":17002,"url":"http:\/\/bangla.sitestree.com\/?p=17002","url_meta":{"origin":16962,"position":4},"title":"Python: Ecommerce: Part \u2014 1: Merge Multiple Supplier Data Files into One File","author":"Sayed","date":"April 19, 2020","format":false,"excerpt":"Section: Merge multiple Supplier Data Files All code in one block #!\/usr\/bin\/env python # coding: utf-8# # Section: Merge multiple Supplier Data Files ## In[1]:# if there is a need to merge multiple files \u2014 use this block import os; import glob; import pandas as pd;# supplier data files\/feeds are\u2026","rel":"","context":"In &quot;Build Ecommerce Software&quot;","block_context":{"text":"Build Ecommerce Software","link":"http:\/\/bangla.sitestree.com\/?cat=1912"},"img":{"alt_text":"8112223 Canada Inc. (Justetc)","src":"https:\/\/miro.medium.com\/fit\/c\/80\/80\/0*P_esmjKoJnHlNjFX","width":350,"height":200},"classes":[]},{"id":17008,"url":"http:\/\/bangla.sitestree.com\/?p=17008","url_meta":{"origin":16962,"position":5},"title":"Python: Ecommerce: Part \u2014 7: Partition a Data File (with product information) into Multiple Files.","author":"Sayed","date":"April 19, 2020","format":false,"excerpt":"In previous steps, we created a product data file to be uploaded to Magento 2 (from supplier data). However, there is a limit, how big a file can be uploaded to Magento 2 for product data import. Hence, this code will divide the data file into multiple files. This data\u2026","rel":"","context":"In &quot;Build Ecommerce Software&quot;","block_context":{"text":"Build Ecommerce Software","link":"http:\/\/bangla.sitestree.com\/?cat=1912"},"img":{"alt_text":"8112223 Canada Inc. (Justetc)","src":"https:\/\/miro.medium.com\/fit\/c\/80\/80\/0*P_esmjKoJnHlNjFX","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/16962","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=16962"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/16962\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16962"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16962"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16962"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}