{"id":17044,"date":"2020-05-09T15:51:36","date_gmt":"2020-05-09T19:51:36","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/calculate-your-categorized-expenses-for-tax-purpose\/"},"modified":"2020-05-09T15:51:36","modified_gmt":"2020-05-09T19:51:36","slug":"calculate-your-categorized-expenses-for-tax-purpose","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=17044","title":{"rendered":"Calculate Your Categorized Expenses for Tax Purpose"},"content":{"rendered":"<h3>Calculate Your Categorized Expenses for Tax Purpose.<\/h3>\n<p> The purpose of this note (i.e. code) is to calculate expenses (revenues) by categories. For the context, read the notes from<\/p>\n<p><a href=\"https:\/\/medium.com\/write-tax-and-financial-software\" title=\"https:\/\/medium.com\/write-tax-and-financial-software\"><strong>Write Tax and Financial Software<\/strong><br \/>\n<em>Code examples in relation to writing Tax and Financial Software<\/em>medium.com<\/a><br \/>\n<img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/cdn-images-1.medium.com\/max\/800\/1%2AjpQZSf1XYnLB7bx2DlaOsg.jpeg?w=750&#038;ssl=1\" alt=\"1*jpQZSf1XYnLB7bx2DlaOsg.jpeg\" \/><\/p>\n<p>At this point, you have spreadsheets for all of your bank accounts and credit cards. You need to merge them into one master sheet. Make sure that you align\/match the columns properly. Some cards will use two columns for debit and credit. Others will just use one with +ve and -ve signs. You will need to separate them into two fields. The master spreadsheet as this code will use used three columns such as \u2018Expense Debit\u2019, \u2018Credit\u2019, \u2018All Money\u2019.<\/p>\n<p>First, you need to find the list of expenses and the associated categories and subcategories. You will also need to put thoughts and decide what goes on which expense categories. A simple way is keep this in your head or in paper\/note, and use them in the code. The simple way.<\/p>\n<p>Well if you are really making a software then it has to be way more structured. A better way to do can be: Put all categories and subcategories in a JSON file (can be enough), or in an xml file (considered worse than JSON), or in a database table such as MySQL\/SQL server table (can be seen as overkill, however, depending\u200a\u2014\u200ayou might find it easier to update (based on size, your skills, tool availability, or writing an UI and DB update code) ). Sure, the last sentence got messy\u200a\u2014\u200ayou know what I mean. I am not trying to be perfectionist here.<\/p>\n<p>The same way, you can keep what goes into what category in JSON\/XML\/Database. You might want to think based on expense description based on which words or cards or accounts\u200a\u2014\u200awhat will go where. Then write the code to assign categories and calculate sum by categories.<\/p>\n<p>The code will simply look for words in the description and based on search result, the category column will be updated. Then the sum will be based on the categories. Yes, you can assign subcategory the same way. And then calculate sum of subcategories.<\/p>\n<p><strong># some simple code are given below<\/strong><\/p>\n<pre>import os;\nimport glob;\nimport pandas as pd;\nimport math;\ndata_folder = \u2018.\/\u2019;\nos.chdir(data_folder);<\/pre>\n<pre># read data, verify data manually\ndf = pd.read_csv(\u2018to_process_all_combined_transactions_assign_category.csv\u2019)\ndf.head(3)<\/pre>\n<pre>#Save to a temp file, to be safe\ndf.to_csv(\u2018temp_to_process_all_combined_transactions_assign_category.csv\u2019);<\/pre>\n<pre># read data, verify data manually\ndf = pd.read_csv(\u2018temp_to_process_all_combined_transactions_assign_category.csv\u2019)\ndf.head(3);<\/pre>\n<pre><strong># Find Donation amount<\/strong> : <strong>FB Fundraiser<\/strong><\/pre>\n<pre><strong>#check<\/strong><\/pre>\n<pre>df[df[\u2018Description 1\u2019].str.contains(\u2018FBFUNDRAISER\u2019, na = False, case = False )][{\u2018Description 1\u2019, \u2018Card Owner\u2019, \u2018Card\u2019, \u2018Expense Debit\u2019}]<\/pre>\n<pre><strong># assign category<\/strong>\ndf.loc[df[\u2018Description 1\u2019].str.contains(\u2018FBFUNDRAISER\u2019, na = False, case = False ), \u2018Category\u2019] = \u2018Donation\u2019<\/pre>\n<pre><strong># keep saving if you want<\/strong>\ndf.to_csv(\u2018temp_to_process_all_combined_transactions_assign_category.csv\u2019);<\/pre>\n<pre><strong># Donation Sum<\/strong>\ndonation = sum(df[df[\u2018Description 1\u2019].str.contains(\u2018FBFUNDRAISER\u2019, na = False, case = False )][\u2018Expense Debit\u2019]);<\/pre>\n<pre>print(\u2018Donation from Business Cards:\u2019, donation);<\/pre>\n<pre><strong># Domain and Hosting Expense<\/strong>\ndf[df[\u2018Description 1\u2019].str.contains(\u2018AWS\u2019, na = False, case = False )][{\u2018Description 1\u2019, \u2018Card Owner\u2019, \u2018Card\u2019, \u2018Expense Debit\u2019}]<\/pre>\n<pre>df.loc[df[\u2018Description 1\u2019].str.contains(\u2018AWS\u2019, na = False, case = False ), \u2018Category\u2019] = \u2018Domain and Hosting\u2019<\/pre>\n<pre>df[df[\u2018Description 1\u2019].str.contains(\u2018HOSTGATOR\u2019, na = False, case = False )][{\u2018Description 1\u2019, \u2018Card Owner\u2019, \u2018Card\u2019, \u2018Expense Debit\u2019}]<\/pre>\n<pre>df.loc[df[\u2018Description 1\u2019].str.contains(\u2018HOSTGATOR\u2019, na = False, case = False ), \u2018Category\u2019] = \u2018Domain and Hosting\u2019<\/pre>\n<pre>df[df[\u2018Description 1\u2019].str.contains(\u2018godaddy\u2019, na = False, case = False )][{\u2018Description 1\u2019, \u2018Card Owner\u2019, \u2018Card\u2019, \u2018Expense Debit\u2019}]<\/pre>\n<pre>df.loc[df[\u2018Description 1\u2019].str.contains(\u2018godaddy\u2019, na = False, case = False ), \u2018Category\u2019] = \u2018Domain and Hosting\u2019<\/pre>\n<pre>df[df[\u2018Description 1\u2019].str.contains(\u2018VULT\u2019, na = False, case = False )][{\u2018Description 1\u2019, \u2018Card Owner\u2019, \u2018Card\u2019, \u2018Expense Debit\u2019}]<\/pre>\n<pre>df.loc[df[\u2018Description 1\u2019].str.contains(\u2018VULT\u2019, na = False, case = False ), \u2018Category\u2019] = \u2018Domain and Hosting\u2019<\/pre>\n<pre>df[df[\u2018Category\u2019].str.contains(\u2018Domain\u2019, na = False, case = False )][{\u2018Description 1\u2019, \u2018Expense Debit\u2019}]<\/pre>\n<pre>domain_hosting = sum(df[df[\u2018Category\u2019].str.contains(\u2018Domain\u2019, na = False, case = False )][\u2018Expense Debit\u2019])<\/pre>\n<pre>print(\u2018Domain from Business Cards:\u2019, domain_hosting);<\/pre>\n<pre>df.to_csv(\u2018temp_to_process_all_combined_transactions_assign_category.csv\u2019);<\/pre>\n<pre><strong># Section Find all Car Gas Expenses<\/strong><\/pre>\n<pre>df.loc[ df[\u2018Description 1\u2019].str.contains(\u2018ESSO\u2019, na = False, case = False ), \u2018Category\u2019 ] = \u2018Car Gas\u2019;\ndf.loc[ df[\u2018Description 1\u2019].str.contains(\u2018SHELL\u2019, na = False, case = False ), \u2018Category\u2019 ] = \u2018Car Gas\u2019;\ndf.loc[ df[\u2018Description 1\u2019].str.contains(\u2018MOBIL Toronto\u2019, na = False, case = False ), \u2018Category\u2019 ] = \u2018Car Gas\u2019;\ndf.loc[ df[\u2018Description 1\u2019].str.contains(\u2018Petro\u2019, na = False, case = False ), \u2018Category\u2019 ] = \u2018Car Gas\u2019;<\/pre>\n<pre><strong># Car Gas Sum<\/strong>\ndf[df[\u2018Category\u2019].str.contains(\u2018Car Gas\u2019, na=False, case=False)] <\/pre>\n<pre>sum(df[df[\u2018Category\u2019].str.contains(\u2018Car Gas\u2019, na=False, case=False)][\u2018Expense Debit\u2019])<\/pre>\n<pre>My goal was not to write great articles; however, share little bit of stuff that I have\n<\/pre>\n<p>*** . *** *** . *** . *** . ***<\/p>\n<p><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><em><strong>Training Courses: <\/strong><a href=\"http:\/\/training.sitestree.com\/\">http:\/\/Training.SitesTree.com<\/a> <\/em><br \/>\nBlog<\/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>8112223 Canada Inc\/Justetc<\/strong>: <a href=\"http:\/\/JustEtc.net\">http:\/\/JustEtc.net<\/a><\/em><br \/>\n<em>Youtube: <\/em><a href=\"https:\/\/www.youtube.com\/channel\/UCHrtq0pV8mEuTLGd2-Lp9ig\/playlists\">https:\/\/www.youtube.com\/channel\/UCHrtq0pV8mEuTLGd2-Lp9ig\/playlists<\/a><br \/>\n<em><strong>Medium: <\/strong><\/em><a href=\"https:\/\/medium.com\/@SayedAhmedCanada\">https:\/\/medium.com\/@SayedAhmedCanada<\/a><\/p>\n<p><em><strong>Facebook Groups\/Forums to discuss (Q &amp; A): <\/strong><\/em><br \/>\n<a href=\"https:\/\/www.facebook.com\/salearningschool\/?ref=your_pages\">https:\/\/www.facebook.com\/salearningschool<\/a><\/p>\n<p><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<p><strong>Join, Discuss, and Thrive:<\/strong><br \/>\nFinance: <a href=\"https:\/\/www.facebook.com\/groups\/1792339521056034\">https:\/\/www.facebook.com\/groups\/1792339521056034<\/a><\/p>\n<p>Bangladesh and Canada: <a href=\"https:\/\/www.facebook.com\/groups\/398414183875009\">https:\/\/www.facebook.com\/groups\/398414183875009<\/a><\/p>\n<p>Bangladesh: IT &amp; Eng: Canada: <a href=\"https:\/\/www.facebook.com\/groups\/480297675634630\">https:\/\/www.facebook.com\/groups\/480297675634630<\/a><\/p>\n<p>BUETians in Ontario: <a href=\"https:\/\/www.facebook.com\/groups\/371982239854027\">https:\/\/www.facebook.com\/groups\/371982239854027<\/a><\/p>\n<p>Worldwide IT: <a href=\"https:\/\/www.facebook.com\/groups\/28362061867\">https:\/\/www.facebook.com\/groups\/28362061867<\/a><\/p>\n<p>JustEtc: <a href=\"https:\/\/www.facebook.com\/JustETC-Technologies-Inc-289864738261\">https:\/\/www.facebook.com\/JustETC-Technologies-Inc-289864738261<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calculate Your Categorized Expenses for Tax Purpose. The purpose of this note (i.e. code) is to calculate expenses (revenues) by categories. For the context, read the notes from Write Tax and Financial Software Code examples in relation to writing Tax and Financial Softwaremedium.com At this point, you have spreadsheets for all of your bank accounts &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=17044\">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-17044","post","type-post","status-publish","format-standard","hentry","category---blog","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":16962,"url":"http:\/\/bangla.sitestree.com\/?p=16962","url_meta":{"origin":17044,"position":0},"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":17005,"url":"http:\/\/bangla.sitestree.com\/?p=17005","url_meta":{"origin":17044,"position":1},"title":"Python: Ecommerce: Part \u2014 4: Calculate Your Sell Prices for your Retail Website, and then calculate for Amazon  and Ebay","author":"Author-Check- Article-or-Video","date":"April 19, 2020","format":false,"excerpt":"The requirements for each of the sales channel can be different such as for Ebay you might want to calculate Paypal fees; for Amazon you have to check for Amazon fees. For your own retail site, shipping cost might need different calculation as well as based on your target audience\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":23421,"url":"http:\/\/bangla.sitestree.com\/?p=23421","url_meta":{"origin":17044,"position":2},"title":"Some Common Expenses (Tax Deductible) for Corporations #Root","author":"Author-Check- Article-or-Video","date":"March 31, 2021","format":false,"excerpt":"\u00a0 Accounting - 8862 Advertising and Promotion (Line 8520) Advertising (Line 8521) Allowance on eligible capital property (Line 9935) Bad debts (Line 8590) Business start-up costs Business tax, fees, licences, dues, memberships, and subscriptions (Line 8760) Business-use-of-home expenses (Line 9945) Capital cost allowance (Line 9936) Current or capital expenses Delivery,\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":[]},{"id":22191,"url":"http:\/\/bangla.sitestree.com\/?p=22191","url_meta":{"origin":17044,"position":3},"title":"Tax Planning Resources, Dividend Tax Credit, Canada, Ontario #Root #Misc. Reading","author":"Author-Check- Article-or-Video","date":"March 11, 2021","format":false,"excerpt":"Some Resources Checked Recently on Taxing (PSB, Small Corporate, and Personal ). These are just information purpose only. We do not recommend to use this information to plan your tax without discussing with an accountant. And treat this post as a draft\/beta. I plan to make the information more accurate\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":[]},{"id":76606,"url":"http:\/\/bangla.sitestree.com\/?p=76606","url_meta":{"origin":17044,"position":4},"title":"Python: MatPlotLib: Plot Data","author":"Sayed","date":"February 6, 2025","format":false,"excerpt":"import pandas as pd import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D columns = [\"J_ID\", \"P_ID\", \"D_ID\", \"Year\", \"JOB_TITLE\", \"Department_Name\", \"Total Salary\", \"Commission\"] df = pd.read_csv(\"datamart.csv\", usecols=columns) # Create a 3D plot fig = plt.figure(figsize=(20, 15)) ax = fig.add_subplot(111, projection='3d') # Scatter plot ax.scatter(df['Year'], df['J_ID'], df['D_ID'], c=df['Total Salary'], cmap='viridis', marker='X')\u2026","rel":"","context":"In &quot;Root&quot;","block_context":{"text":"Root","link":"http:\/\/bangla.sitestree.com\/?cat=1"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/02\/image-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/02\/image-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/bangla.sitestree.com\/wp-content\/uploads\/2025\/02\/image-1.png?resize=525%2C300 1.5x"},"classes":[]},{"id":17007,"url":"http:\/\/bangla.sitestree.com\/?p=17007","url_meta":{"origin":17044,"position":5},"title":"Python: Ecommerce: Part \u2014 6: Format and adjust your product data and price data to save to a csv to upload to  Magento 2.","author":"Sayed","date":"April 19, 2020","format":false,"excerpt":"Code will be given cell by cell from Jupyter Notebook. Then will also give all code in one block. You might need to adjust the indenting a bit. Read the code comments as well. Comments explained the sections. In [86]: # calculate\/adjust data so that we can create magento 2\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\/17044","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=17044"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/17044\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17044"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}