Published Date : 2020年12月3日18:05

2/5 給与所得者の所得税と住民税を計算してみよう
2/5 Let's calculate the income tax and resident tax for salaried workers


This blog has an English translation


YouTubeにアップした動画、「【日本語解説】2/5 給与所得者の所得税と住民税を計算してみよう」の補足説明の記事です。

Here's a little more about the 「【Python】2/5 Let's calculate the income tax and resident tax for salaried workers」 video I uploaded to YouTube.

字幕を付けるなら、英語音声と日本語音声の二つに分けたほうが良いと思ったので、今回から同じ動画だが音声が日本語と英語に分かれたものをアップしました。

I thought it would be better to separate the video into English audio and Japanese audio instead of adding subtitles to the video, so I uploaded the same video with Japanese and English audio separately.

ページの頭に日本語解説動画、ページの最後に英語解説動画のリンクが貼られてます。

There is a Japanese explanation video at the top of the page, and an English explanation video link at the end of the page.


目次

Table of Contents




① 動画の説明
① Video Description



警告:

今回説明する給与所得者の所得税及び住民税を計算するツールは、あくまで簡易的なお遊び用のツールです。

正確な数値、計算方法は各自で調べて下さい。

このツールは大雑把に大体の見積りを計算して楽しむ為のツールです。

決して従業員の年末調整や個人の確定申告等に使用しないでください。

さらに、税金の計算方法は変更される場合があり、控除についても同様です。

また、控除や税金の計算方法が間違っている可能性もありますので、

あまり信用せずに、各自で調べてから実験してみてください。

このツールを使って何かしらの損害が発生したとしても、私は一切の責任を負いません。

Warning:

​The tool I'm going to show you for calculating income and residence taxes for salaried workers is just a simple tool for playing.

​Please check the exact number and calculation method by yourself.

​This tool is used to calculate rough estimates and enjoy them.

​Do not use for year-end adjustment of employees or for individual tax return.

In addition, the method of calculating taxes and deductions may change.

Also, there is a possibility that the deduction and tax calculation methods are incorrect.

Don't trust it too much, and test it yourself.

​I will not be liable for any damage caused by using this tool.

続いて、健康保険と厚生年金保険料の表のPDFを健保協会のサイトからダウンロードします。

​Next, download the PDF of the table of health insurance and welfare pension premiums from the website of National Health Insurance Association.

ダウンロードしたPDFをいつものようにテキストファイルにします。

Make the downloaded PDF a text file as usual.

Pandasでデータフレームにして整理したいので、個別のCSVファイルに分けます。

​I want to organize it by data frame in Pandas, so I divide it into individual CSV files.

そして、一つのCSVファイルにまとめます。

​It then integrates into a single CSV file.

concat_df = pd.concat([concat_df, df], axis=1)

使わなくなったファイルを別のフォルダへ移します。

Move the files you no longer need to another folder.

入力した給与収入に対応する健康保険、雇用保険料が導き出せるようにします。

​Enable to derive health insurance and employment insurance premiums corresponding to the salary income entered.

concat_df[(concat_df['月額円以上'] <= monthly_salary) & (concat_df['月額円未満'] > monthly_salary)]

前回までに作成したクラスファイルにメソッドととして追加します。

​Add these scripts as methods to the previously created class files.

def social_insurance_deduction(self):

メインファイルにPandasとMathモジュールを追加して、実際に健康保険、雇用保険料を算出する関数を作成します。

​Add the Pandas and Math modules to the main file to create a function that actually calculates health and employment insurance premiums.

from taxcalc import TaxCalc
import pandas as pd
import math

続いて、金融庁のサイトへアクセスして、各種控除について入力できるように、計算方法の下調べを行います。

​Next, go to the Financial Services Agency site and do a preliminary examination of the calculation method so that you can enter various deductions.

クラスファイルに各種控除を加えていきます。

Add various deductions to the class file.

準備ができたら一度テストをしてみましょう。

​When you're ready, try the script.

分かりやすくするため、大きくなってしまったスクリプトファイルを複数のファイルに分割していきます。

​To make it easier to understand, we will split a script file with too many lines into multiple files.

クラスファイルも同様に複数のクラスファイルに分割して管理しやすくしましょう。

Class files should likewise be divided into multiple class files to make them easier to manage.

これらの作業は必ずしも必要となる訳ではないので、各自で好きなように行ってくだちぃ。

However, these tasks are not always necessary, so ​you decide whether you want to edit it or leave it as it is.

クラスを継承させているのは単純に見やすくするためなので、もしもっといいやり方があるならその通りに行ってください。

Inheriting classes is done simply to make them easier to see, so if you have a better way, do it that way.

スクリプトを動かして、挙動を確かめてみましょう。

​Let's run the script and see how it works.



以上です。お疲れ様です。

That's all. Thank you for your hard work.