世界最古のビジネス¶

シュタッフェルター ホフ ワイナリーは、カロリング朝時代の 862 年に設立されたドイツ最古のワイナリーです。神聖ローマ帝国、オスマン帝国、両世界大戦など、ヨーロッパの劇的な変化の中でもお客様にサービスを提供し続けてきました。ビジネスが時の試練に耐えることを可能にする特性は何ですか?

1. データについて¶

この質問に答えるために、BusinessFinancing.co.ukの 調査 は、ほぼすべての国で現在も事業を行っている最古の企業です。国を調査し、その結果をデータセットにまとめました。これらの歴史的なビジネスをより深く理解するために、この取り組みを検討してみましょう。データセットはすべて「datasets」ディレクトリにあり、次の情報が含まれています。
元のデータソースはこちらのエクセルファイルと思われます。

businesses.csvとnew_businesses.csv

コラム タイプ 意味
business varchar 事業所の名前
year_founded int ビジネスが設立された年
category_code varchar ビジネスのカテゴリのコード
country_code の文字 の ISO 3166-1 3 文字の国コード

county.csv

列 タイプ 意味
country_code varchar ISO 3166-1 3 文字の国コード
country varchar 国の名前
continent varchar 国が存在する大陸の名前

category

列 タイプ 意味
category_code varchar ビジネスのカテゴリのコード
category varchar ビジネス カテゴリの説明

では、今も運営されている世界最古のビジネスについて調べてみます。

from zipfile import ZipFile
from io import BytesIO
import pandas as pd

zf = ZipFile('datasets.zip')
zf.namelist()
['datasets/',
 'datasets/categories.csv',
 'datasets/new_businesses.csv',
 'datasets/countries.csv',
 'datasets/businesses.csv']
categories = pd.read_csv(BytesIO(zf.read(zf.namelist()[1])))
new_businesses = pd.read_csv(BytesIO(zf.read(zf.namelist()[2])))
countries = pd.read_csv(BytesIO(zf.read(zf.namelist()[3])))
businesses = pd.read_csv(BytesIO(zf.read(zf.namelist()[4])))
sorted_businesses = businesses.sort_values(['year_founded'])

sorted_businesses.head()
business year_founded category_code country_code
64 Kongō Gumi 578 CAT6 JPN
94 St. Peter Stifts Kulinarium 803 CAT4 AUT
107 Staffelter Hof Winery 862 CAT9 DEU
106 Monnaie de Paris 864 CAT12 FRA
103 The Royal Mint 886 CAT12 GBR

2. 北米で最も古い企業¶

これまでのところ、金剛組は 2 番目に古い企業を 100 年以上も引き離し、継続的に運営されている世界で最も古い企業であることがわかりました。
ただし、国番号を読むのは少し難しいです。国コードと一緒に国名のリストがあれば便利だと思います。

countries.csv を使用します。これもdatasets.zip にあります。有用な情報をさまざまなファイルに保存することはよくある問題です。データ ストレージの場合は、さまざまな種類のデータを別々に保存する方が良いですが、分析の場合はすべてのデータを 1 か所にまとめたいと考えます。これを解決するには、2 つのテーブルを結合する必要があります。

countries.csv

列 タイプ 意味
country_code varchar ISO 3166-1 3 文字の国コード
country varchar 国の名前
continent varchar 国が存在する大陸の名前

「countries.csv」には「continent」列が含まれているため、データセットを結合すると、各大陸で最も古いビジネスを確認することもできます。

# sorted_businesss を国と統合する
businesses_countries = sorted_businesses.merge(countries, on='country_code')

# 北米の国のみを含めるように businesss_countries をフィルタリング
north_america = businesses_countries[businesses_countries['continent']=='North America']
north_america.head()
business year_founded category_code country_code country continent
22 La Casa de Moneda de México 1534 CAT12 MEX Mexico North America
28 Shirley Plantation 1638 CAT1 USA United States North America
33 Hudson's Bay Company 1670 CAT17 CAN Canada North America
35 Mount Gay Rum 1703 CAT9 BRB Barbados North America
40 Rose Hall 1770 CAT19 JAM Jamaica North America

3. 各大陸で最も古いビジネス¶

さて、北米で最も古い企業は、1534 年に設立されたLa Casa de Moneda de México であることがわかります。しかし、各大陸で最も古い企業を簡単に見つけることができるのに、なぜそこで止まるのでしょうか。

# 大陸を作成します。大陸と最も古い year_founded のみがリストされます。
continent = pd.DataFrame(businesses_countries.groupby('continent').min()['year_founded'])

# 大陸をbusiness_countryと結合する
merged_continent = continent.merge(businesses_countries)

# 対象となる 4 つの列のみが含まれるように大陸をサブセットします
subset_merged_continent = merged_continent[['continent', 'country', 'business',  'year_founded']]
subset_merged_continent.head()
continent country business year_founded
0 Africa Mauritius Mauritius Post 1772
1 Asia Japan Kongō Gumi 578
2 Europe Austria St. Peter Stifts Kulinarium 803
3 North America Mexico La Casa de Moneda de México 1534
4 Oceania Australia Australia Post 1809

4. 知られざる最古のビジネス¶

BusinessFinancing.co.uk は一部の国で最も古いビジネスを特定できず、それらの国は単純に「businesses.csv」、ひいては「businesses」から除外されています。ただし、作成したcountriesには、最も古いビジネスが知られているかどうかに関係なく、世界のすべての国が含まれます。

1 つのデータフレーム内の 2 つのデータセットを比較して、既知の最も古いビジネスが存在しない国を見つけることができます。

#  .merge() を使用して DataFrame、all_countries を作成します
all_countries = businesses.merge(countries, on='country_code', how='right', indicator=True)

# 最も古いビジネスがない国のみを含むようにフィルターします。
missing_countries = all_countries[all_countries['_merge'] != 'both']

# 最も古いビジネス データが欠落している一連の国名を作成します
missing_countries_series = missing_countries['country']

missing_countries_series
1                                Angola
7                   Antigua and Barbuda
18                              Bahamas
48                   Dominican Republic
50                              Ecuador
57                                 Fiji
59      Micronesia, Federated States of
63                                Ghana
65                               Gambia
69                              Grenada
79            Iran, Islamic Republic of
89                           Kyrgyzstan
91                             Kiribati
92                Saint Kitts and Nevis
107                              Monaco
108                Moldova, Republic of
110                            Maldives
112                    Marshall Islands
131                               Nauru
138                               Palau
139                    Papua New Guinea
143                            Paraguay
144                 Palestine, State of
153                     Solomon Islands
160                            Suriname
170                          Tajikistan
171                        Turkmenistan
172                         Timor-Leste
173                               Tonga
177                              Tuvalu
185    Saint Vincent and the Grenadines
189                               Samoa
Name: country, dtype: object

5. 最も古いビジネスデータを新たに追加する¶

データセットにいくつかの穴があるようです。幸いなことに、私たちは BusinessFinancing.co.uk の仕事を改善し、行方不明のいくつかの国で最も古いビジネスを見つけることに自ら取り組んできました。新しく見つかった最も古いビジネスは、datasets/new_businesses.csv にある new_businesses に保存されました。これは、ビジネス データセットとまったく同じ構造を持っています。

new_businesses.csv

コラム タイプ 意味
business varchar 事業所の名前
year_founded int ビジネスが設立された年
category_code varchar ビジネスのカテゴリのコード
country_code ISO 3166-1 3 文字の国コード

私たちがしなければならないのは、この 2 つを組み合わせて、ビジネスの完全なリストをもう 1 つ作成することだけです。

# new_businesses のデータを既存のビジネスに追加します
all_businesses = pd.concat([new_businesses, businesses])

# マージとフィルタリングを行って、ビジネス データが欠落している国を見つけます
new_all_countries = all_businesses.merge(countries, on='country_code', how='right', indicator=True)
new_missing_countries = new_all_countries[new_all_countries['_merge'] != 'both']
new_missing_countries

# 大陸ごとにグループ化し、「count_missing」列を作成します
count_missing = new_missing_countries.groupby('continent').agg({'country': 'count'})
count_missing.columns = ['count_missing']
count_missing
count_missing
continent
Africa 3
Asia 7
Europe 2
North America 5
Oceania 10
South America 3

6. 最古の産業¶

世界最古の企業、金剛組を覚えていますか?

business year_founded category_code country_code
64 金剛組 578 CAT6 JPN

金剛組が日本で 578 年に設立されたことはわかっていますが、どの業界に属しているのかを解読するのは少し難しいです。category_code 列が何を参照しているかについての情報は、"datasets/categories.csv" にあります。

「カテゴリー」

列 タイプ 意味
category_code varchar ビジネスのカテゴリのコード。
カテゴリー varchar ビジネス カテゴリの説明。

「categories.csv」を使用して、各業界カテゴリに最も古い企業が何社あるかを理解してみましょう。

businesses_categories = businesses.merge(categories, on='category_code')

#  各カテゴリの最も古いビジネスの数をリストするデータフレームを作成します。
count_business_cats = businesses_categories.groupby('category').agg({'business': 'count'})

# # 列の名前を変更し、DataFrame の最初の 5 行を表示します
count_business_cats.columns = ['count']
display(count_business_cats.head())
count
category
Agriculture 6
Aviation & Transport 19
Banking & Finance 37
Cafés, Restaurants & Bars 6
Conglomerate 3

7. 最古のレストランを探す¶

どう評価しても、長寿が私たちの目標であれば、銀行と金融は素晴らしい業界であるように見えます。別の業界、カフェ、レストラン、バーにズームインしてみましょう。データセット内の 1800 年以前から存在するレストランはどれですか?

# 1800 年より前に設立された CAT4 ビジネスの場合は、.query() を使用してフィルターします。  結果を並べ替える
old_restaurants = businesses_categories[businesses_categories['category'] == "Cafés, Restaurants & Bars"].query('year_founded <= 1800')

# データフレームを並べ替える
old_restaurants = old_restaurants.sort_values('year_founded')
old_restaurants
business year_founded category_code country_code category
142 St. Peter Stifts Kulinarium 803 CAT4 AUT Cafés, Restaurants & Bars
143 Sean's Bar 900 CAT4 IRL Cafés, Restaurants & Bars
139 Ma Yu Ching's Bucket Chicken House 1153 CAT4 CHN Cafés, Restaurants & Bars

8. カテゴリと大陸¶

セント ピーター スティフツ クリナリウムは、このレストランがモーツァルトを提供したと考えられているほど古いもので、モーツァルトが常連だったときでも 900 年以上の歴史があることになります。最後に、各大陸の各商業カテゴリーにおける最も古いビジネスを見てみましょう。

# すべてのビジネス、国、カテゴリーを統合する
businesses_categories_countries = businesses.merge(categories).merge(countries)

# business_categories_countries を古いものから新しいものへ並べ替えます
businesses_categories_countries = businesses_categories_countries.sort_values('year_founded')

# 大陸およびカテゴリごとに最も古いデータフレームを作成する
oldest_by_continent_category = businesses_categories_countries.groupby(['continent','category']).agg({'year_founded':'min'})
oldest_by_continent_category
year_founded
continent category
Africa Agriculture 1947
Aviation & Transport 1854
Banking & Finance 1892
Distillers, Vintners, & Breweries 1933
Energy 1968
Food & Beverages 1878
Manufacturing & Production 1820
Media 1943
Mining 1962
Postal Service 1772
Asia Agriculture 1930
Aviation & Transport 1858
Banking & Finance 1830
Cafés, Restaurants & Bars 1153
Conglomerate 1841
Construction 578
Defense 1808
Distillers, Vintners, & Breweries 1853
Energy 1928
Food & Beverages 1820
Manufacturing & Production 1736
Media 1931
Mining 1913
Postal Service 1800
Retail 1883
Telecommunications 1885
Tourism & Hotels 1584
Europe Agriculture 1218
Banking & Finance 1606
Cafés, Restaurants & Bars 803
Consumer Goods 1649
Defense 1878
Distillers, Vintners, & Breweries 862
Manufacturing & Production 864
Media 1999
Medical 1422
Mining 1248
Postal Service 1520
Telecommunications 1912
Tourism & Hotels 1230
North America Agriculture 1638
Aviation & Transport 1870
Banking & Finance 1891
Distillers, Vintners, & Breweries 1703
Food & Beverages 1920
Manufacturing & Production 1534
Media 1909
Retail 1670
Tourism & Hotels 1770
Oceania Banking & Finance 1861
Postal Service 1809
South America Banking & Finance 1565
Cafés, Restaurants & Bars 1877
Defense 1811
Food & Beverages 1660
Manufacturing & Production 1621

データビジュアライズ¶

世界地図上に表示する¶

import folium
import mplleaflet
import matplotlib.pyplot as plt

m = folium.Map()

Geoデータの取得

# geo = ("http://geojson.xyz/naturalearth-3.3.0/ne_50m_admin_0_countries.geojson")
geo = "ne_50m_admin_0_countries.geojson" # at local

Foliumで地図データを作成
geoデータ、使用するデータフレームを指定して地図を表示

m = folium.Map(location=(30, 65), zoom_start=3, tiles="cartodb positron")
folium.Choropleth(
                geo_data = geo,
                data = new_all_countries,
                columns = ["country", "year_founded"],
                key_on = "feature.properties.name",
                fill_color="RdYlBu",
                fill_opacity=0.8,
                line_opacity=0.3,
                bins = 30,
                nan_fill_color="white",
                legend_name="The Oldtest Business in Each Countries",
                ).add_to(m)

display(m)
Make this Notebook Trusted to load map: File -> Trust Notebook

データ検証¶

ロシア、韓国など一部の国が正しく表示されていないのでデータを訂正する必要がある

geoデータのjsonから国名、カントリーコードを取得してjsonからデータフレームを作成する。
カントリーコードは2桁、3桁があるため両方取得。
3桁のコードを使用してデータをマージするためカラム名をcountry_codeにする。

data = pd.read_json(geo)

df_data = []
for feature in data["features"]:
    properties = feature["properties"]
    admin = properties.get("name", None)
    iso_a2 = properties.get("iso_a2", None)
    iso_a3 = properties.get("iso_a3", None)
    df_data.append({"name": admin, "iso_a2": iso_a2, "country_code": iso_a3})

    
df_json = pd.DataFrame(df_data)
df_json.head()
name iso_a2 country_code
0 Aruba AW ABW
1 Afghanistan AF AFG
2 Angola AO AGO
3 Anguilla AI AIA
4 Albania AL ALB

取得したデータフレームとマージする。 nanは不要のため削除。

json_merged = new_all_countries.dropna().merge(df_json, on="country_code")
json_merged.sample(5)
business year_founded category_code country_code country continent _merge name iso_a2
121 Bochnia Salt Mine 1248.0 CAT15 POL Poland Europe both Poland PL
102 Mongolian National Broadcaster 1931.0 CAT13 MNG Mongolia Asia both Mongolia MN
58 Halco Mining 1962.0 CAT15 GIN Guinea Africa both Guinea GN
122 Kim Chong-t'ae Electric Locomotive Works 1945.0 CAT2 PRK Korea, Democratic People's Republic of Asia both Dem. Rep. Korea KP
86 Umma Bank 1907.0 CAT3 LBY Libya Africa both Libya LY
world_map = folium.Map(location=(30, 65), zoom_start=3, tiles="cartodb positron")
folium.Choropleth(
                geo_data = geo,
                data = json_merged,
                columns = ["name", "year_founded"],
                key_on = "feature.properties.name",
                fill_color="RdYlBu",
                fill_opacity=0.8,
                line_opacity=0.4,
                bins = 40,
                nan_fill_color="white",
                legend_name="The Oldtest Business in Each Countries",
                ).add_to(world_map)

title_html = """
<div style="font-size: 24px;"><b>Most Oldest Business World Map</b></div>
"""
world_map.get_root().html.add_child(folium.Element(title_html))

world_map
Make this Notebook Trusted to load map: File -> Trust Notebook

各国にマーカーを追加する¶

各国の代表的な緯度経度を取得するためにkaggleページからのデータを使用する。

lat_long_country = pd.read_csv('world_country_and_usa_states_latitude_and_longitude_values.csv')
lat_long_country.sample(5)
country_code latitude longitude country usa_state_code usa_state_latitude usa_state_longitude usa_state
131 LU 49.815273 6.129583 Luxembourg NaN NaN NaN NaN
184 RE -21.115141 55.536384 Réunion NaN NaN NaN NaN
81 GM 13.443182 -15.310139 Gambia NaN NaN NaN NaN
161 NI 12.865416 -85.207229 Nicaragua NaN NaN NaN NaN
25 BM 32.321384 -64.757370 Bermuda MS 32.354668 -89.398528 Mississippi

country_code,country,latitude,longitude 以外の余分な欄も不要なためデータを限定する。

lat_long = lat_long_country.iloc[:,:3]
lat_long.head()
country_code latitude longitude
0 AD 42.546245 1.601554
1 AE 23.424076 53.847818
2 AF 33.939110 67.709953
3 AG 17.060816 -61.796428
4 AI 18.220554 -63.068615

データをマージして新しくmerged_dfを作成

merged_df = pd.merge(json_merged, lat_long, left_on='iso_a2', right_on='country_code',how='inner')

year_foundedをintに変換

merged_df.year_founded = merged_df.year_founded.astype(int)

作成したデータフレームを使用してマーカーを追加

for index, row in merged_df.iterrows():
    tooltip_html = f'<b>{row.business}</b><br>Founded <i>{row.year_founded}</i> in <i>{row.country}</i>'
    
    folium.Marker(
        location = [row['latitude'], row['longitude']],
        tooltip = tooltip_html,
        
        icon = folium.Icon(icon='flag', 
                           icon_color='rgba(250, 250, 250, 0.9)',
                           shadow_size = (0,0),
                           color = 'green',
                          )
    ).add_to(world_map)


world_map
Make this Notebook Trusted to load map: File -> Trust Notebook

マーカーにマウスを当てるとその国の最も古いビジネスの情報が表示されます。


以上、世界最古のビジネスを探し、各国の最も古いビジネスをビジュアル化しました。