Python:日本の自動車輸出入を詳細(適当)に考察する

その買うを、もっとハッピーに。|ハピタス

日本の輸入車市場はドイツの一強状態だが、ドイツはどれくらい日本車を輸入しているか気になるところだ。日本車なんかイラネというドイツ人が多いことは容易に想像が付くが、日本のドイツ車購入額とドイツの日本車購入額を、このサイトを参考にしながら比較することで、ドイツ人の日本車に対する意識をグラフ化してみる。

スポンサーリンク

日本はどこに自動車を輸出しているのか

このサイトからデータをダウンロードしてくる。

from pandas import *

df = read_csv('comtrade.csv',usecols=['Year', 'Period','Trade Flow','Reporter', 'Partner', 'Commodity','Commodity Code','Trade Value (US$)'])
df.head()
Year Period Trade Flow Reporter Partner Commodity Code Commodity Trade Value (US$)
0 2018 201808 Exports Japan Belgium 8702 Vehicles; public transport passenger type 127996
1 2018 201808 Exports Japan Bermuda 8702 Vehicles; public transport passenger type 136163
2 2018 201808 Exports Japan Cambodia 8702 Vehicles; public transport passenger type 189918
3 2018 201808 Exports Japan Cyprus 8702 Vehicles; public transport passenger type 32028
4 2018 201808 Exports Japan Cayman Isds 8702 Vehicles; public transport passenger type 21889
df_world = df[df['Partner'] == 'World']
df_countries = df[df['Partner'] != 'World']
df_exports = df[df['Trade Flow'] == 'Exports']
df_countries_exports = df_countries[df_countries['Trade Flow'] == 'Exports']
df_world_exports=df_world[df_world['Trade Flow'] == 'Exports']
df_countries_exports.sort_values('Trade Value (US$)',ascending=False).head(12)
Year Period Trade Flow Reporter Partner Commodity Code Commodity Trade Value (US$)
3539 2018 201811 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 3877304496
2255 2018 201802 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 3737613322
3328 2018 201810 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 3622257927
2686 2018 201804 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 3575398739
2293 2018 201803 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 3533440519
1829 2018 201809 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 3336289841
1284 2018 201807 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 3284538781
3110 2018 201806 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 3222161832
1444 2018 201808 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 2989504367
1947 2018 201801 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 2678998724
2732 2018 201805 Exports Japan United States of America 8703 Motor cars and other motor vehicles; principal… 2635027408
1509 2018 201810 Exports Japan China 8703 Motor cars and other motor vehicles; principal… 701109590

ドルを円(1ドル=111円)に変換する

a=df_countries[df_countries["Trade Flow"]=='Exports'].groupby(['Partner'])['Trade Value (US$)'].aggregate(sum)
for i in range(len(a)):
    a[i] = a[i]*111
a.sort_values(ascending=False).head()
Partner
United States of America    4050745045266
Australia                    651941139489
China                        582547171254
United Arab Emirates         451783433331
Canada                       356740662018
Name: Trade Value (US$), dtype: int64
rcParams["font.size"] = "17"
fig, ax = subplots(figsize=(20,12))

a.sort_values(ascending=False, inplace=False).head(40).plot(ax=ax,kind='barh',color='g')
xticks(np.arange(0,4.5e12,1e12/2),
  ['{}兆'.format(float(x/1e12)) if x > 0 else 0 for x in np.arange(0,4.5e12,1e12/2)])
ax.legend(["輸出額"],loc='upper right', prop={'size': 26})
<matplotlib.legend.Legend at 0x7fc19a7924e0>

アメリカが圧倒的に強い。あまりにも強過ぎる。どれくらい強いのかと言うと、下を見れば一目瞭然だろう。

a = DataFrame(a)
a = a.sort_values('Trade Value (US$)',ascending=False)
sum(a['Trade Value (US$)'][1:17])
4060312345167

アメリカ一国で、2位〜16位の国の輸出額合計とほぼ匹敵している。トランプ大統領が怒るのも無理はないだろう。しかしながら、2018年のアメリカへの自動車輸出額は、このサイトによると4兆5241億円となっている。これは、今回使用したデータの12月分が抜けているためである。

スポンサーリンク

日本の自動車輸出入額

Trade Value (US$)を円に変換する。

df_countries['Trade Value (US$)']=df_countries['Trade Value (US$)'].mul(111)
/root/.pyenv/versions/miniconda3-latest/envs/py368/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  """Entry point for launching an IPython kernel.

pandasのpivot_tableを使って輸入額順に並べる。

report = pivot_table(df_countries.loc[df_countries['Trade Value (US$)']>1e6],
               index=['Year','Partner'],
               columns='Trade Flow',
               values='Trade Value (US$)',
               aggfunc=sum)

#And then display the result, sorted by import value
c = report.sort_values('Imports', ascending=False).head(24)
from matplotlib.pyplot import *
from matplotlib.font_manager import FontProperties
from matplotlib import rcParams
import matplotlib.patches as mpatches
style.use('ggplot')

rcParams["font.size"] = "18"
fp = FontProperties(fname='/usr/share/fonts/opentype/ipaexfont-gothic/ipaexg.ttf', size=54)
rcParams['font.family'] = fp.get_name()
rcParams["font.size"] = "17"
fig, ax = subplots(figsize=(20,12))

c.plot(ax=ax, kind='barh')
xticks(np.arange(0,4.5e12,1e12/2),
  ['{}兆'.format(float(x/1e12)) if x > 0 else 0 for x in np.arange(0,4.5e12,1e12/2)]);

輸入はドイツが圧倒的に多いが、輸出はアメリカが圧倒的に多い。ドイツへの輸出は輸入の3分の1程度であるが、ドイツと日本の人口比を考えると実際には2分の1程度と見なすことができる。何れにしても、日本人にとってドイツ車は魅力的であるが、10%の関税は別として、ドイツ人にとって日本車はそれほど魅力的ではないと結論付けることができるだろう。関税は別としてと述べたのは、日本の自動車関税は確かにゼロだが、国内販売店のボッタ価格が酷過ぎで、実質的に莫大な関税が課せられているのと変わらないと一部の識者達に指摘されているからだ。

スポンサーリンク
スポンサーリンク