In [ ]:
!pip install geopandas
Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ Collecting geopandas Using cached geopandas-0.12.2-py3-none-any.whl (1.1 MB) Requirement already satisfied: shapely>=1.7 in /usr/local/lib/python3.9/dist-packages (from geopandas) (2.0.1) Requirement already satisfied: pandas>=1.0.0 in /usr/local/lib/python3.9/dist-packages (from geopandas) (1.4.4) Requirement already satisfied: packaging in /usr/local/lib/python3.9/dist-packages (from geopandas) (23.0) Collecting fiona>=1.8 Using cached Fiona-1.9.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.1 MB) Collecting pyproj>=2.6.1.post1 Using cached pyproj-3.4.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.7 MB) Requirement already satisfied: attrs>=19.2.0 in /usr/local/lib/python3.9/dist-packages (from fiona>=1.8->geopandas) (22.2.0) Requirement already satisfied: certifi in /usr/local/lib/python3.9/dist-packages (from fiona>=1.8->geopandas) (2022.12.7) Requirement already satisfied: importlib-metadata in /usr/local/lib/python3.9/dist-packages (from fiona>=1.8->geopandas) (6.1.0) Requirement already satisfied: click~=8.0 in /usr/local/lib/python3.9/dist-packages (from fiona>=1.8->geopandas) (8.1.3) Collecting cligj>=0.5 Using cached cligj-0.7.2-py3-none-any.whl (7.1 kB) Collecting munch>=2.3.2 Using cached munch-2.5.0-py2.py3-none-any.whl (10 kB) Collecting click-plugins>=1.0 Using cached click_plugins-1.1.1-py2.py3-none-any.whl (7.5 kB) Requirement already satisfied: numpy>=1.18.5 in /usr/local/lib/python3.9/dist-packages (from pandas>=1.0.0->geopandas) (1.22.4) Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.9/dist-packages (from pandas>=1.0.0->geopandas) (2022.7.1) Requirement already satisfied: python-dateutil>=2.8.1 in /usr/local/lib/python3.9/dist-packages (from pandas>=1.0.0->geopandas) (2.8.2) Requirement already satisfied: six in /usr/local/lib/python3.9/dist-packages (from munch>=2.3.2->fiona>=1.8->geopandas) (1.16.0) Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.9/dist-packages (from importlib-metadata->fiona>=1.8->geopandas) (3.15.0) Installing collected packages: pyproj, munch, cligj, click-plugins, fiona, geopandas Successfully installed click-plugins-1.1.1 cligj-0.7.2 fiona-1.9.2 geopandas-0.12.2 munch-2.5.0 pyproj-3.4.1
In [ ]:
import pandas as pd
import geopandas as gpd
In [ ]:
df = pd.read_excel('/content/grape.xlsx')
In [ ]:
df.head()
Out[ ]:
Countries | 2011 | 2012 | 2013 | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Belgium | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | Bulgaria | 243.8 | 260.67 | 325.6 | 132.73 | 261.82 | 211.08 | 202.44 | 201.53 | 178.53 | 159.1 | 178.3 |
2 | Czechia | 91.25 | 59.99 | 74.72 | 63.53 | 90.61 | 75.91 | 79.77 | 103.7 | 67.96 | 90.38 | 90.06 |
3 | Denmark | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
4 | Germany (until 1990 former territory of the FRG) | : | : | : | : | : | : | : | : | : | : | : |
In [ ]:
print(df.columns)
Index(['Countries', 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021], dtype='object')
In [ ]:
df.columns = df.columns.astype(str)
In [ ]:
print(df.columns)
Index(['Countries', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021'], dtype='object')
In [ ]:
df[df.columns[1:]] = df[df.columns[1:]].replace([':'], int(0))
In [ ]:
df
Out[ ]:
Countries | 2011 | 2012 | 2013 | 2014 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Belgium | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
1 | Bulgaria | 243.80 | 260.67 | 325.60 | 132.73 | 261.82 | 211.08 | 202.44 | 201.53 | 178.53 | 159.10 | 178.30 |
2 | Czechia | 91.25 | 59.99 | 74.72 | 63.53 | 90.61 | 75.91 | 79.77 | 103.70 | 67.96 | 90.38 | 90.06 |
3 | Denmark | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
4 | Germany (until 1990 former territory of the FRG) | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
5 | Estonia | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
6 | Ireland | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
7 | Greece | 932.86 | 997.21 | 1082.78 | 1071.44 | 1037.52 | 1027.48 | 1012.58 | 933.15 | 807.57 | 815.79 | 739.66 |
8 | Spain | 5809.32 | 5566.62 | 7480.02 | 6221.66 | 5799.13 | 6102.85 | 5387.40 | 6983.26 | 5745.45 | 6817.77 | 6086.92 |
9 | France | 6649.09 | 5379.74 | 5540.84 | 6204.91 | 6258.40 | 6018.13 | 5011.05 | 6267.79 | 5489.65 | 5884.23 | 4493.53 |
10 | Croatia | 204.37 | 187.55 | 181.10 | 134.94 | 154.23 | 123.65 | 116.31 | 146.24 | 108.30 | 123.55 | 116.63 |
11 | Italy | 7115.60 | 6903.76 | 8010.36 | 6930.79 | 7649.48 | 8248.53 | 7169.75 | 8513.64 | 7900.12 | 8222.36 | 8149.40 |
12 | Cyprus | 25.11 | 20.58 | 20.39 | 20.19 | 21.74 | 23.37 | 22.87 | 22.38 | 22.76 | 23.57 | 24.12 |
13 | Latvia | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
14 | Lithuania | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
15 | Luxembourg | 17.57 | 11.32 | 13.43 | 16.63 | 14.74 | 11.04 | 10.89 | 18.10 | 10.16 | 12.95 | 13.36 |
16 | Hungary | 449.87 | 356.36 | 451.12 | 406.03 | 472.35 | 476.49 | 529.59 | 533.07 | 457.25 | 435.05 | 426.35 |
17 | Malta | 3.92 | 5.52 | 5.26 | 5.36 | 5.11 | 3.71 | 3.63 | 4.11 | 3.24 | 2.89 | 2.65 |
18 | Netherlands | 0.00 | 0.00 | 0.00 | 0.00 | 1.48 | 1.40 | 1.60 | 1.70 | 1.60 | 1.70 | 1.93 |
19 | Austria | 375.30 | 287.30 | 318.93 | 266.49 | 302.45 | 260.34 | 331.43 | 367.13 | 309.92 | 319.79 | 328.04 |
20 | Poland | 1.20 | 1.50 | 3.10 | 3.40 | 3.00 | 3.18 | 2.77 | 3.92 | 3.21 | 3.20 | 3.80 |
21 | Portugal | 746.51 | 841.62 | 827.75 | 818.87 | 935.08 | 800.74 | 896.09 | 802.08 | 864.85 | 853.38 | 854.27 |
22 | Romania | 873.91 | 742.07 | 988.13 | 779.77 | 794.94 | 733.11 | 1063.34 | 1140.57 | 973.99 | 932.77 | 991.10 |
23 | Slovenia | 121.40 | 92.38 | 100.20 | 94.28 | 117.70 | 94.89 | 89.52 | 127.13 | 105.20 | 103.78 | 84.30 |
24 | Slovakia | 49.02 | 52.21 | 53.22 | 38.45 | 50.16 | 37.83 | 45.86 | 52.42 | 43.04 | 46.92 | 44.07 |
25 | Finland | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
26 | Sweden | 0.01 | 0.04 | 0.05 | 0.09 | 0.07 | 0.07 | 0.05 | 0.06 | 0.07 | 0.16 | 0.13 |
27 | Iceland | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
28 | Liechtenstein | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
29 | Norway | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 | 0.00 |
30 | Switzerland | 0.00 | 0.00 | 0.00 | 106.31 | 106.31 | 133.04 | 100.29 | 140.64 | 123.85 | 104.28 | 0.00 |
31 | United Kingdom | 0.00 | 0.00 | 0.00 | 2.70 | 4.01 | 4.00 | 9.31 | 15.19 | 14.60 | 0.00 | 0.00 |
32 | Montenegro | 22.13 | 25.08 | 24.15 | 17.13 | 23.09 | 28.93 | 22.20 | 24.44 | 20.86 | 21.27 | 0.00 |
33 | North Macedonia | 235.10 | 240.46 | 292.07 | 195.89 | 324.77 | 333.32 | 180.35 | 294.50 | 258.96 | 317.55 | 269.13 |
34 | Albania | 195.20 | 197.00 | 0.00 | 203.70 | 205.00 | 205.00 | 202.90 | 110.40 | 113.90 | 118.80 | 0.00 |
35 | Serbia | 193.98 | 149.22 | 199.96 | 122.49 | 170.65 | 145.83 | 145.90 | 149.59 | 163.52 | 160.30 | 155.72 |
36 | Turkey | 4296.00 | 4185.00 | 4011.00 | 4175.00 | 3650.00 | 4000.00 | 4200.00 | 3933.00 | 4100.00 | 4209.00 | 0.00 |
37 | Bosnia and Herzegovina | 21.60 | 25.93 | 31.80 | 26.22 | 32.21 | 36.31 | 28.01 | 40.41 | 39.29 | 44.70 | 42.01 |
38 | Kosovo (under United Nations Security Council ... | 16.60 | 29.70 | 27.60 | 26.70 | 26.40 | 22.20 | 15.40 | 27.30 | 19.30 | 26.33 | 0.00 |
In [ ]:
df_n = df.set_index('Countries')
In [ ]:
df_n['2021'].nlargest(3)
Out[ ]:
Countries Italy 8149.40 Spain 6086.92 France 4493.53 Name: 2021, dtype: float64
In [ ]:
df_wine = pd.read_csv("/content/wine.csv")
In [ ]:
df_wine.head()
Out[ ]:
country | wineProduction | wineProductionGallons | pop2022 | |
---|---|---|---|---|
0 | Italy | 4250000 | 1122731 | 60262.770 |
1 | France | 3641900 | 962088 | 65584.518 |
2 | Spain | 3248000 | 858030 | 46719.142 |
3 | United States | 2333900 | 616551 | 334805.269 |
4 | Australia | 1369000 | 361651 | 26068.792 |
In [ ]:
df_wine.columns = df_wine.columns.str.replace('country', 'Countries')
In [ ]:
df_wine.head()
Out[ ]:
Countries | wineProduction | wineProductionGallons | pop2022 | |
---|---|---|---|---|
0 | Italy | 4250000 | 1122731 | 60262.770 |
1 | France | 3641900 | 962088 | 65584.518 |
2 | Spain | 3248000 | 858030 | 46719.142 |
3 | United States | 2333900 | 616551 | 334805.269 |
4 | Australia | 1369000 | 361651 | 26068.792 |
In [ ]:
df_grape2017 = df[['Countries','2017']]
In [ ]:
df_grape2017['Countries'].iloc[4] = df_grape2017['Countries'].iloc[4].replace("Germany (until 1990 former territory of the FRG)", "Germany")
<ipython-input-18-2d039ce4f076>:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df_grape2017['Countries'].iloc[4] = df_grape2017['Countries'].iloc[4].replace("Germany (until 1990 former territory of the FRG)", "Germany")
In [ ]:
df_grape2017
Out[ ]:
Countries | 2017 | |
---|---|---|
0 | Belgium | 0.00 |
1 | Bulgaria | 202.44 |
2 | Czechia | 79.77 |
3 | Denmark | 0.00 |
4 | Germany | 0.00 |
5 | Estonia | 0.00 |
6 | Ireland | 0.00 |
7 | Greece | 1012.58 |
8 | Spain | 5387.40 |
9 | France | 5011.05 |
10 | Croatia | 116.31 |
11 | Italy | 7169.75 |
12 | Cyprus | 22.87 |
13 | Latvia | 0.00 |
14 | Lithuania | 0.00 |
15 | Luxembourg | 10.89 |
16 | Hungary | 529.59 |
17 | Malta | 3.63 |
18 | Netherlands | 1.60 |
19 | Austria | 331.43 |
20 | Poland | 2.77 |
21 | Portugal | 896.09 |
22 | Romania | 1063.34 |
23 | Slovenia | 89.52 |
24 | Slovakia | 45.86 |
25 | Finland | 0.00 |
26 | Sweden | 0.05 |
27 | Iceland | 0.00 |
28 | Liechtenstein | 0.00 |
29 | Norway | 0.00 |
30 | Switzerland | 100.29 |
31 | United Kingdom | 9.31 |
32 | Montenegro | 22.20 |
33 | North Macedonia | 180.35 |
34 | Albania | 202.90 |
35 | Serbia | 145.90 |
36 | Turkey | 4200.00 |
37 | Bosnia and Herzegovina | 28.01 |
38 | Kosovo (under United Nations Security Council ... | 15.40 |
In [ ]:
df_grape2017 = df_grape2017.set_index('Countries')
In [ ]:
df_wine['Countries'].iloc[28] = df_wine['Countries'].iloc[28].replace("Czech Republic", "Czechia")
<ipython-input-21-6bea7214a6d5>:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy df_wine['Countries'].iloc[28] = df_wine['Countries'].iloc[28].replace("Czech Republic", "Czechia")
In [ ]:
df_wine.iloc[28]
Out[ ]:
Countries Czechia wineProduction 64500 wineProductionGallons 17039 pop2022 10736.784 Name: 28, dtype: object
In [ ]:
df_wine = df_wine.set_index('Countries')
In [ ]:
df_common = df_grape2017.loc[df_grape2017.index.isin(df_wine.index)] #useless
In [ ]:
import numpy as np
In [ ]:
df_wine.index = df_wine.index.str.upper()
In [ ]:
df_grape2017.index = df_grape2017.index.str.upper()
In [ ]:
df_wine2017 = df_grape2017.join(df_wine)
In [ ]:
df_wine2017
Out[ ]:
2017 | wineProduction | wineProductionGallons | pop2022 | |
---|---|---|---|---|
Countries | ||||
BELGIUM | 0.00 | 700.0 | 184.0 | 11668.278 |
BULGARIA | 202.44 | 108000.0 | 28530.0 | 6844.597 |
CZECHIA | 79.77 | 64500.0 | 17039.0 | 10736.784 |
DENMARK | 0.00 | NaN | NaN | NaN |
GERMANY | 0.00 | 746200.0 | 197125.0 | 83883.596 |
ESTONIA | 0.00 | 12000.0 | 3170.0 | 1321.910 |
IRELAND | 0.00 | NaN | NaN | NaN |
GREECE | 1012.58 | 255000.0 | 67363.0 | 10316.637 |
SPAIN | 5387.40 | 3248000.0 | 858030.0 | 46719.142 |
FRANCE | 5011.05 | 3641900.0 | 962088.0 | 65584.518 |
CROATIA | 116.31 | 72600.0 | 19178.0 | 4059.286 |
ITALY | 7169.75 | 4250000.0 | 1122731.0 | 60262.770 |
CYPRUS | 22.87 | 11000.0 | 2905.0 | 1223.387 |
LATVIA | 0.00 | 2300.0 | 607.0 | 1848.837 |
LITHUANIA | 0.00 | 4100.0 | 1083.0 | 2661.708 |
LUXEMBOURG | 10.89 | 9000.0 | 2377.0 | 642.371 |
HUNGARY | 529.59 | 318000.0 | 84006.0 | 9606.259 |
MALTA | 3.63 | 1500.0 | 396.0 | 444.033 |
NETHERLANDS | 1.60 | NaN | NaN | NaN |
AUSTRIA | 331.43 | 248600.0 | 65673.0 | 9066.710 |
POLAND | 2.77 | NaN | NaN | NaN |
PORTUGAL | 896.09 | 673700.0 | 177972.0 | 10140.570 |
ROMANIA | 1063.34 | 431700.0 | 114043.0 | 19031.335 |
SLOVENIA | 89.52 | 47300.0 | 12495.0 | 2078.034 |
SLOVAKIA | 45.86 | 29800.0 | 7872.0 | 5460.193 |
FINLAND | 0.00 | NaN | NaN | NaN |
SWEDEN | 0.05 | NaN | NaN | NaN |
ICELAND | 0.00 | NaN | NaN | NaN |
LIECHTENSTEIN | 0.00 | NaN | NaN | NaN |
NORWAY | 0.00 | NaN | NaN | NaN |
SWITZERLAND | 100.29 | 79200.0 | 20922.0 | 8773.637 |
UNITED KINGDOM | 9.31 | 3000.0 | 792.0 | 68497.907 |
MONTENEGRO | 22.20 | 14800.0 | 3909.0 | 627.950 |
NORTH MACEDONIA | 180.35 | NaN | NaN | NaN |
ALBANIA | 202.90 | 17800.0 | 4702.0 | 2866.374 |
SERBIA | 145.90 | 99300.0 | 26232.0 | 8653.016 |
TURKEY | 4200.00 | 64400.0 | 17012.0 | 85561.976 |
BOSNIA AND HERZEGOVINA | 28.01 | 6000.0 | 1585.0 | 3249.317 |
KOSOVO (UNDER UNITED NATIONS SECURITY COUNCIL RESOLUTION 1244/99) | 15.40 | NaN | NaN | NaN |
In [ ]:
print(df_wine2017[['2017', 'wineProduction']].isnull().any())
2017 False wineProduction True dtype: bool
In [ ]:
df_wine2017[df_wine2017.columns[1:]] = df_wine2017[df_wine2017.columns[1:]].fillna(0)
In [ ]:
df_wine2017['2017'] = df_wine2017['2017']*1000
In [ ]:
df_wine2017
Out[ ]:
2017 | wineProduction | wineProductionGallons | pop2022 | |
---|---|---|---|---|
Countries | ||||
BELGIUM | 0.0 | 700.0 | 184.0 | 11668.278 |
BULGARIA | 202440.0 | 108000.0 | 28530.0 | 6844.597 |
CZECHIA | 79770.0 | 64500.0 | 17039.0 | 10736.784 |
DENMARK | 0.0 | 0.0 | 0.0 | 0.000 |
GERMANY | 0.0 | 746200.0 | 197125.0 | 83883.596 |
ESTONIA | 0.0 | 12000.0 | 3170.0 | 1321.910 |
IRELAND | 0.0 | 0.0 | 0.0 | 0.000 |
GREECE | 1012580.0 | 255000.0 | 67363.0 | 10316.637 |
SPAIN | 5387400.0 | 3248000.0 | 858030.0 | 46719.142 |
FRANCE | 5011050.0 | 3641900.0 | 962088.0 | 65584.518 |
CROATIA | 116310.0 | 72600.0 | 19178.0 | 4059.286 |
ITALY | 7169750.0 | 4250000.0 | 1122731.0 | 60262.770 |
CYPRUS | 22870.0 | 11000.0 | 2905.0 | 1223.387 |
LATVIA | 0.0 | 2300.0 | 607.0 | 1848.837 |
LITHUANIA | 0.0 | 4100.0 | 1083.0 | 2661.708 |
LUXEMBOURG | 10890.0 | 9000.0 | 2377.0 | 642.371 |
HUNGARY | 529590.0 | 318000.0 | 84006.0 | 9606.259 |
MALTA | 3630.0 | 1500.0 | 396.0 | 444.033 |
NETHERLANDS | 1600.0 | 0.0 | 0.0 | 0.000 |
AUSTRIA | 331430.0 | 248600.0 | 65673.0 | 9066.710 |
POLAND | 2770.0 | 0.0 | 0.0 | 0.000 |
PORTUGAL | 896090.0 | 673700.0 | 177972.0 | 10140.570 |
ROMANIA | 1063340.0 | 431700.0 | 114043.0 | 19031.335 |
SLOVENIA | 89520.0 | 47300.0 | 12495.0 | 2078.034 |
SLOVAKIA | 45860.0 | 29800.0 | 7872.0 | 5460.193 |
FINLAND | 0.0 | 0.0 | 0.0 | 0.000 |
SWEDEN | 50.0 | 0.0 | 0.0 | 0.000 |
ICELAND | 0.0 | 0.0 | 0.0 | 0.000 |
LIECHTENSTEIN | 0.0 | 0.0 | 0.0 | 0.000 |
NORWAY | 0.0 | 0.0 | 0.0 | 0.000 |
SWITZERLAND | 100290.0 | 79200.0 | 20922.0 | 8773.637 |
UNITED KINGDOM | 9310.0 | 3000.0 | 792.0 | 68497.907 |
MONTENEGRO | 22200.0 | 14800.0 | 3909.0 | 627.950 |
NORTH MACEDONIA | 180350.0 | 0.0 | 0.0 | 0.000 |
ALBANIA | 202900.0 | 17800.0 | 4702.0 | 2866.374 |
SERBIA | 145900.0 | 99300.0 | 26232.0 | 8653.016 |
TURKEY | 4200000.0 | 64400.0 | 17012.0 | 85561.976 |
BOSNIA AND HERZEGOVINA | 28010.0 | 6000.0 | 1585.0 | 3249.317 |
KOSOVO (UNDER UNITED NATIONS SECURITY COUNCIL RESOLUTION 1244/99) | 15400.0 | 0.0 | 0.0 | 0.000 |
In [ ]:
df_wine2017 = df_wine2017[df_wine2017["wineProduction"]!=0].dropna()
In [ ]:
df_wine2017
Out[ ]:
2017 | wineProduction | wineProductionGallons | pop2022 | |
---|---|---|---|---|
Countries | ||||
BELGIUM | 0.0 | 700.0 | 184.0 | 11668.278 |
BULGARIA | 202440.0 | 108000.0 | 28530.0 | 6844.597 |
CZECHIA | 79770.0 | 64500.0 | 17039.0 | 10736.784 |
GERMANY | 0.0 | 746200.0 | 197125.0 | 83883.596 |
ESTONIA | 0.0 | 12000.0 | 3170.0 | 1321.910 |
GREECE | 1012580.0 | 255000.0 | 67363.0 | 10316.637 |
SPAIN | 5387400.0 | 3248000.0 | 858030.0 | 46719.142 |
FRANCE | 5011050.0 | 3641900.0 | 962088.0 | 65584.518 |
CROATIA | 116310.0 | 72600.0 | 19178.0 | 4059.286 |
ITALY | 7169750.0 | 4250000.0 | 1122731.0 | 60262.770 |
CYPRUS | 22870.0 | 11000.0 | 2905.0 | 1223.387 |
LATVIA | 0.0 | 2300.0 | 607.0 | 1848.837 |
LITHUANIA | 0.0 | 4100.0 | 1083.0 | 2661.708 |
LUXEMBOURG | 10890.0 | 9000.0 | 2377.0 | 642.371 |
HUNGARY | 529590.0 | 318000.0 | 84006.0 | 9606.259 |
MALTA | 3630.0 | 1500.0 | 396.0 | 444.033 |
AUSTRIA | 331430.0 | 248600.0 | 65673.0 | 9066.710 |
PORTUGAL | 896090.0 | 673700.0 | 177972.0 | 10140.570 |
ROMANIA | 1063340.0 | 431700.0 | 114043.0 | 19031.335 |
SLOVENIA | 89520.0 | 47300.0 | 12495.0 | 2078.034 |
SLOVAKIA | 45860.0 | 29800.0 | 7872.0 | 5460.193 |
SWITZERLAND | 100290.0 | 79200.0 | 20922.0 | 8773.637 |
UNITED KINGDOM | 9310.0 | 3000.0 | 792.0 | 68497.907 |
MONTENEGRO | 22200.0 | 14800.0 | 3909.0 | 627.950 |
ALBANIA | 202900.0 | 17800.0 | 4702.0 | 2866.374 |
SERBIA | 145900.0 | 99300.0 | 26232.0 | 8653.016 |
TURKEY | 4200000.0 | 64400.0 | 17012.0 | 85561.976 |
BOSNIA AND HERZEGOVINA | 28010.0 | 6000.0 | 1585.0 | 3249.317 |
In [ ]:
import plotly.express as px
import plotly.graph_objs as go
import plotly as pl
In [ ]:
#df_2017 = df_wine2017['2017'].loc[:]
In [ ]:
#df_w_2017 = df_wine2017['wineProduction'].loc[:]
In [ ]:
df_wine2017 = df_wine2017.drop(df_wine2017.columns[[2, 3]], axis=1)
In [ ]:
df_wine2017
Out[ ]:
2017 | wineProduction | |
---|---|---|
Countries | ||
BELGIUM | 0.0 | 700.0 |
BULGARIA | 202440.0 | 108000.0 |
CZECHIA | 79770.0 | 64500.0 |
GERMANY | 0.0 | 746200.0 |
ESTONIA | 0.0 | 12000.0 |
GREECE | 1012580.0 | 255000.0 |
SPAIN | 5387400.0 | 3248000.0 |
FRANCE | 5011050.0 | 3641900.0 |
CROATIA | 116310.0 | 72600.0 |
ITALY | 7169750.0 | 4250000.0 |
CYPRUS | 22870.0 | 11000.0 |
LATVIA | 0.0 | 2300.0 |
LITHUANIA | 0.0 | 4100.0 |
LUXEMBOURG | 10890.0 | 9000.0 |
HUNGARY | 529590.0 | 318000.0 |
MALTA | 3630.0 | 1500.0 |
AUSTRIA | 331430.0 | 248600.0 |
PORTUGAL | 896090.0 | 673700.0 |
ROMANIA | 1063340.0 | 431700.0 |
SLOVENIA | 89520.0 | 47300.0 |
SLOVAKIA | 45860.0 | 29800.0 |
SWITZERLAND | 100290.0 | 79200.0 |
UNITED KINGDOM | 9310.0 | 3000.0 |
MONTENEGRO | 22200.0 | 14800.0 |
ALBANIA | 202900.0 | 17800.0 |
SERBIA | 145900.0 | 99300.0 |
TURKEY | 4200000.0 | 64400.0 |
BOSNIA AND HERZEGOVINA | 28010.0 | 6000.0 |
In [ ]:
df_wine2017 = df_wine2017.reset_index(level=0)
In [ ]:
df_wine2017
Out[ ]:
Countries | 2017 | wineProduction | |
---|---|---|---|
0 | BELGIUM | 0.0 | 700.0 |
1 | BULGARIA | 202440.0 | 108000.0 |
2 | CZECHIA | 79770.0 | 64500.0 |
3 | GERMANY | 0.0 | 746200.0 |
4 | ESTONIA | 0.0 | 12000.0 |
5 | GREECE | 1012580.0 | 255000.0 |
6 | SPAIN | 5387400.0 | 3248000.0 |
7 | FRANCE | 5011050.0 | 3641900.0 |
8 | CROATIA | 116310.0 | 72600.0 |
9 | ITALY | 7169750.0 | 4250000.0 |
10 | CYPRUS | 22870.0 | 11000.0 |
11 | LATVIA | 0.0 | 2300.0 |
12 | LITHUANIA | 0.0 | 4100.0 |
13 | LUXEMBOURG | 10890.0 | 9000.0 |
14 | HUNGARY | 529590.0 | 318000.0 |
15 | MALTA | 3630.0 | 1500.0 |
16 | AUSTRIA | 331430.0 | 248600.0 |
17 | PORTUGAL | 896090.0 | 673700.0 |
18 | ROMANIA | 1063340.0 | 431700.0 |
19 | SLOVENIA | 89520.0 | 47300.0 |
20 | SLOVAKIA | 45860.0 | 29800.0 |
21 | SWITZERLAND | 100290.0 | 79200.0 |
22 | UNITED KINGDOM | 9310.0 | 3000.0 |
23 | MONTENEGRO | 22200.0 | 14800.0 |
24 | ALBANIA | 202900.0 | 17800.0 |
25 | SERBIA | 145900.0 | 99300.0 |
26 | TURKEY | 4200000.0 | 64400.0 |
27 | BOSNIA AND HERZEGOVINA | 28010.0 | 6000.0 |
In [ ]:
df_wine2017 = df_wine2017.nlargest(5, ['2017'])
In [ ]:
df_wine2017
Out[ ]:
Countries | 2017 | wineProduction | |
---|---|---|---|
9 | ITALY | 7169750.0 | 4250000.0 |
6 | SPAIN | 5387400.0 | 3248000.0 |
7 | FRANCE | 5011050.0 | 3641900.0 |
26 | TURKEY | 4200000.0 | 64400.0 |
18 | ROMANIA | 1063340.0 | 431700.0 |
In [ ]:
df_wine2017 = df_wine2017.assign(Percentage = lambda x: df_wine2017['wineProduction']*100
/ df_wine2017['2017'])
In [ ]:
"""
percentage_sym = []
percentage_sym = list(df_wine2017['Percentage'])
for ind, i in enumerate(percentage_sym):
percentage_sym[ind] = str(i)+'%'
i = int(i)
"""
#choropleth haritasında çalışmıyor çünkü string.
Out[ ]:
"\npercentage_sym = []\npercentage_sym = list(df_wine2017['Percentage'])\nfor ind, i in enumerate(percentage_sym):\n percentage_sym[ind] = str(i)+'%'\n i = int(i)\n"
In [ ]:
#df_wine2017['Percentage'] = percentage_sym
In [ ]:
mask = pd.to_numeric(df_wine2017['2017']).notnull()
df_wine2017['2017'] = df_wine2017['2017'].loc[mask].astype(np.int64)
df_wine2017['wineProduction'] = df_wine2017['wineProduction'].loc[mask].astype(np.int64) #removing 0 after '.'
In [ ]:
df_wine2017 = df_wine2017.reset_index(level=0)
In [ ]:
a = df_wine2017['2017'].iloc[:]
In [ ]:
b = df_wine2017['wineProduction'].iloc[:]
In [ ]:
z = df_wine2017['Countries'].iloc[:]
In [ ]:
y = df_wine2017['Percentage'].iloc[:]
In [ ]:
def merge(a, b,z, y):
merged_list = [(a[i], b[i],z[i], y[i]) for i in range(0, len(a))]
return merged_list
In [ ]:
c = merge(a,b,z, y)
In [ ]:
import matplotlib.pyplot as plt
In [ ]:
#c = zip(a,b)
In [ ]:
#list = zip()
In [ ]:
#list(c)
In [ ]:
#del list
In [ ]:
d = list(zip(*c))
In [ ]:
d
Out[ ]:
[(7169750, 5387400, 5011050, 4200000, 1063340), (4250000, 3248000, 3641900, 64400, 431700), ('ITALY', 'SPAIN', 'FRANCE', 'TURKEY', 'ROMANIA'), (59.27682276229994, 60.288822066302856, 72.67738298360624, 1.5333333333333334, 40.59849154550755)]
In [ ]:
#c.sort(key=lambda x: x[1], reverse=True)
# save the names and their respective scores separately
# reverse the tuples to go from most frequent to least frequent
grape = d[0]
wine = d[1]
country = d[2]
percentage = d[3]
x_pos = np.arange(len(grape))
# calculate slope and intercept for the linear trend line
slope, intercept = np.polyfit(grape, wine, 1)
trendline = intercept + (slope * x_pos)
#plt.plot(grape, trendline, color='red', linestyle='--')
#fig, ax1 = plt.subplots() yarın bunu kullanarak yap
def merge2(country, wine):
merged_list = [(country[i], grape[i]) for i in range(0, len(country))]
return merged_list
c_w = merge2(country, wine) #country ve wine'ı birleştirip bir liste oluşturarak lejantta sırasıyla göstermeyi hedefliyorum. Henüz başarılı değil.
plt.figure(figsize=(40, 10))
plt.bar(country, grape,align='center')
plt.bar(country, wine, bottom=0, align='center')
plt.xticks(x_pos, country)
plt.yticks(grape)
#plt.twiny(plt.yticks(wine)) hatalı
plt.ylabel('Production of grapes by each top 5 country')
plt.ticklabel_format(style='plain', axis='y')
columns = ('','','','','')
rows = ['Grape Production', 'Wine Production', 'Percentage']
grape = list(grape)
wine = list(wine)
def list_to_str(grape, wine):
for i in range(0, len(grape)):
grape[i] = '{:,}'.format(grape[i])
wine[i] = '{:,}'.format(wine[i])
list_to_str(grape, wine)
grape = tuple(grape)
wine = tuple(wine)
cell_text = [grape, wine, percentage]
colors = plt.cm.tab10(np.linspace(0.15, 0.05, 3)) #2 değerli bir liste oluşturdum
colors = colors[::-1]
the_table = plt.table(cellText=cell_text,
rowLabels=rows,
colLabels=columns,
rowColours = colors,
loc='bottom')
plt.subplots_adjust(bottom=-1.0)
plt.show()
In [ ]:
df_borders = gpd.read_file('/content/Europe.shp')
In [ ]:
df_borders
Out[ ]:
NAME | ORGN_NAME | geometry | |
---|---|---|---|
0 | Albania | Shqipëria | MULTIPOLYGON (((19.50115 40.96230, 19.50563 40... |
1 | Andorra | Andorra | POLYGON ((1.43992 42.60649, 1.45041 42.60596, ... |
2 | Austria | Österreich | POLYGON ((16.00000 48.77775, 16.00000 48.78252... |
3 | Belgium | België / Belgique | POLYGON ((5.00000 49.79374, 4.99724 49.79696, ... |
4 | Bosnia Herzegovina | Bosna i Hercegovina | POLYGON ((19.22947 43.53458, 19.22925 43.53597... |
5 | Croatia | Hrvatska | MULTIPOLYGON (((14.30038 44.50156, 14.28972 44... |
6 | Czech Republic | Cesko | POLYGON ((14.82523 50.87399, 14.83687 50.86996... |
7 | Denmark | Danmark | MULTIPOLYGON (((11.99978 54.94118, 11.98534 54... |
8 | Estonia | Eesti | MULTIPOLYGON (((23.97511 58.09691, 23.96645 58... |
9 | Finland | Suomi | MULTIPOLYGON (((22.07310 60.22830, 22.06502 60... |
10 | France | France | MULTIPOLYGON (((-2.28137 46.68570, -2.31121 46... |
11 | Germany | Deutschland | MULTIPOLYGON (((13.11717 54.54924, 13.12529 54... |
12 | Gibraltar (UK) | Gibraltar (UK) | POLYGON ((-5.35322 36.15980, -5.34003 36.15975... |
13 | Greece | Elláda | MULTIPOLYGON (((24.74283 37.59560, 24.73534 37... |
14 | Guernsey (UK) | Guernsey (UK) | MULTIPOLYGON (((-2.52483 49.48867, -2.52034 49... |
15 | Hungary | Magyarország | POLYGON ((22.32725 48.36194, 22.32294 48.32583... |
16 | Ireland | Éire / Ireland | MULTIPOLYGON (((-10.21726 51.74543, -10.22042 ... |
17 | Isle of Man (UK) | Isle of Man (UK) | MULTIPOLYGON (((-4.38349 54.32594, -4.37470 54... |
18 | Italy | Italia | MULTIPOLYGON (((12.46117 37.88075, 12.45686 37... |
19 | Jersey (UK) | Jersey (UK) | POLYGON ((-2.03507 49.19905, -2.03699 49.19314... |
20 | Latvia | Latvija | POLYGON ((22.14997 57.64129, 22.17712 57.65100... |
21 | Liechtenstein | Liechtenstein | POLYGON ((9.53591 47.27354, 9.56037 47.24912, ... |
22 | Lithuania | Lietuva | MULTIPOLYGON (((26.22030 55.00000, 26.21693 54... |
23 | Luxembourg | Lëtzebuerg / Luxemburg / Luxembourg | POLYGON ((6.13802 50.13290, 6.14092 50.12927, ... |
24 | Macedonia | Makedonija | POLYGON ((22.37382 42.32667, 22.37228 42.32576... |
25 | Malta | Malta | MULTIPOLYGON (((14.33938 36.00751, 14.33490 36... |
26 | Monaco | Monaco | POLYGON ((7.40680 43.73196, 7.40175 43.73449, ... |
27 | Montenegro | Crna Gora | MULTIPOLYGON (((19.22947 43.53458, 19.22795 43... |
28 | Netherlands | Nederland | MULTIPOLYGON (((6.05039 53.44675, 6.04538 53.4... |
29 | Norway | Norge | MULTIPOLYGON (((14.82404 68.21677, 14.80662 68... |
30 | Poland | Polska | MULTIPOLYGON (((14.21288 53.86478, 14.21349 53... |
31 | Portugal | Portugal | MULTIPOLYGON (((-25.83763 37.88595, -25.83689 ... |
32 | San Marino | San Marino | POLYGON ((12.51004 43.99981, 12.51557 43.99566... |
33 | Serbia | Srbija | POLYGON ((18.83875 45.90742, 18.86463 45.91018... |
34 | Slovakia | Slovensko | POLYGON ((18.85061 49.52131, 18.85416 49.51941... |
35 | Slovenia | Slovenija | POLYGON ((16.56602 46.48372, 16.54178 46.48717... |
36 | Spain | España | MULTIPOLYGON (((-5.60904 36.00032, -5.61149 36... |
37 | Sweden | Sverige | MULTIPOLYGON (((16.69817 57.43244, 16.69456 57... |
38 | Switzerland | Schweiz / Suisse / Svizerra / Svizra | POLYGON ((9.53591 47.27354, 9.52660 47.25858, ... |
39 | United Kingdom | United Kingdom | MULTIPOLYGON (((-5.33523 51.85830, -5.34557 51... |
40 | Armenia | Hayastan | MULTIPOLYGON (((45.48185 40.65776, 45.49001 40... |
41 | Azerbaijan | Azerbaycan | MULTIPOLYGON (((49.02264 39.19647, 49.02892 39... |
42 | Belarus | Belarus | POLYGON ((30.00000 51.48946, 29.95314 51.48722... |
43 | Bulgaria | Balgarija | POLYGON ((22.68183 44.21765, 22.68898 44.21381... |
44 | Faeroe Islands (Denmark) | Foroyar (Danmark) | MULTIPOLYGON (((-6.37378 62.23575, -6.38222 62... |
45 | Georgia | Sakartvelo | POLYGON ((40.01024 43.38326, 40.01102 43.39860... |
46 | Iceland | Ísland | MULTIPOLYGON (((-15.38783 64.35684, -15.39691 ... |
47 | Jan Mayen (Norway) | Jan Mayen (Norge) | POLYGON ((-8.13727 71.14619, -8.09449 71.14722... |
48 | Moldova | Moldova | POLYGON ((27.72524 48.45466, 27.74713 48.45837... |
49 | Romania | România | MULTIPOLYGON (((29.59458 44.81385, 29.57739 44... |
50 | Svalbard (Norway) | Svalbard (Norge) | MULTIPOLYGON (((20.80218 78.56455, 20.80361 78... |
51 | Turkey | Türkiye | MULTIPOLYGON (((29.11932 40.83066, 29.11734 40... |
52 | Ukraine | Ukrajina | MULTIPOLYGON (((33.52988 45.87363, 33.52778 45... |
53 | Russia | Rossíya | MULTIPOLYGON (((52.65438 71.45161, 52.64216 71... |
In [ ]:
df_borders_w = df_borders.set_index('NAME')
In [ ]:
df_borders_w = df_borders_w.loc[df_borders_w.index.isin(['Italy', 'Spain', 'France', 'Turkey', 'Romania'])]
In [ ]:
df_borders_w
Out[ ]:
ORGN_NAME | geometry | |
---|---|---|
NAME | ||
France | France | MULTIPOLYGON (((-2.28137 46.68570, -2.31121 46... |
Italy | Italia | MULTIPOLYGON (((12.46117 37.88075, 12.45686 37... |
Spain | España | MULTIPOLYGON (((-5.60904 36.00032, -5.61149 36... |
Romania | România | MULTIPOLYGON (((29.59458 44.81385, 29.57739 44... |
Turkey | Türkiye | MULTIPOLYGON (((29.11932 40.83066, 29.11734 40... |
In [ ]:
#df_borders_w = df_borders_w.reset_index(level=0)
In [ ]:
df_borders_w
Out[ ]:
ORGN_NAME | geometry | |
---|---|---|
NAME | ||
France | France | MULTIPOLYGON (((-2.28137 46.68570, -2.31121 46... |
Italy | Italia | MULTIPOLYGON (((12.46117 37.88075, 12.45686 37... |
Spain | España | MULTIPOLYGON (((-5.60904 36.00032, -5.61149 36... |
Romania | România | MULTIPOLYGON (((29.59458 44.81385, 29.57739 44... |
Turkey | Türkiye | MULTIPOLYGON (((29.11932 40.83066, 29.11734 40... |
In [ ]:
df_borders_w.index = df_borders_w.index.str.upper()
In [ ]:
df_borders_w
Out[ ]:
ORGN_NAME | geometry | |
---|---|---|
NAME | ||
FRANCE | France | MULTIPOLYGON (((-2.28137 46.68570, -2.31121 46... |
ITALY | Italia | MULTIPOLYGON (((12.46117 37.88075, 12.45686 37... |
SPAIN | España | MULTIPOLYGON (((-5.60904 36.00032, -5.61149 36... |
ROMANIA | România | MULTIPOLYGON (((29.59458 44.81385, 29.57739 44... |
TURKEY | Türkiye | MULTIPOLYGON (((29.11932 40.83066, 29.11734 40... |
In [ ]:
df_wine2017 = df_wine2017.set_index('Countries')
In [ ]:
df_borders_w = df_borders_w.join(df_wine2017)
In [ ]:
df_borders_w
Out[ ]:
ORGN_NAME | geometry | index | 2017 | wineProduction | Percentage | |
---|---|---|---|---|---|---|
NAME | ||||||
FRANCE | France | MULTIPOLYGON (((-2.28137 46.68570, -2.31121 46... | 7 | 5011050 | 3641900 | 72.677383 |
ITALY | Italia | MULTIPOLYGON (((12.46117 37.88075, 12.45686 37... | 9 | 7169750 | 4250000 | 59.276823 |
SPAIN | España | MULTIPOLYGON (((-5.60904 36.00032, -5.61149 36... | 6 | 5387400 | 3248000 | 60.288822 |
ROMANIA | România | MULTIPOLYGON (((29.59458 44.81385, 29.57739 44... | 18 | 1063340 | 431700 | 40.598492 |
TURKEY | Türkiye | MULTIPOLYGON (((29.11932 40.83066, 29.11734 40... | 26 | 4200000 | 64400 | 1.533333 |
In [ ]:
plot_dict = df_borders_w['wineProduction']
In [ ]:
plot_dict
Out[ ]:
NAME FRANCE 3641900 ITALY 4250000 SPAIN 3248000 ROMANIA 431700 TURKEY 64400 Name: wineProduction, dtype: int64
In [ ]:
df_borders_w = df_borders_w.reset_index(level=0)
In [ ]:
df_borders_w
Out[ ]:
NAME | ORGN_NAME | geometry | index | 2017 | wineProduction | Percentage | |
---|---|---|---|---|---|---|---|
0 | FRANCE | France | MULTIPOLYGON (((-2.28137 46.68570, -2.31121 46... | 7 | 5011050 | 3641900 | 72.677383 |
1 | ITALY | Italia | MULTIPOLYGON (((12.46117 37.88075, 12.45686 37... | 9 | 7169750 | 4250000 | 59.276823 |
2 | SPAIN | España | MULTIPOLYGON (((-5.60904 36.00032, -5.61149 36... | 6 | 5387400 | 3248000 | 60.288822 |
3 | ROMANIA | România | MULTIPOLYGON (((29.59458 44.81385, 29.57739 44... | 18 | 1063340 | 431700 | 40.598492 |
4 | TURKEY | Türkiye | MULTIPOLYGON (((29.11932 40.83066, 29.11734 40... | 26 | 4200000 | 64400 | 1.533333 |
In [ ]:
df_borders_w = df_borders_w.nlargest(5, ['2017']) #bir önceki dataframe ile aynı sıralmaya sahip olması için
In [ ]:
df_borders_boun = df_borders_w[['NAME', 'geometry']].set_index('NAME')
In [ ]:
df_borders_boun
Out[ ]:
geometry | |
---|---|
NAME | |
ITALY | MULTIPOLYGON (((12.46117 37.88075, 12.45686 37... |
SPAIN | MULTIPOLYGON (((-5.60904 36.00032, -5.61149 36... |
FRANCE | MULTIPOLYGON (((-2.28137 46.68570, -2.31121 46... |
TURKEY | MULTIPOLYGON (((29.11932 40.83066, 29.11734 40... |
ROMANIA | MULTIPOLYGON (((29.59458 44.81385, 29.57739 44... |
In [ ]:
import folium
from folium import Choropleth, Circle, Marker
from folium import Choropleth, Circle, Marker
from folium.plugins import HeatMap, MarkerCluster
In [ ]:
import branca.colormap as cmp
In [ ]:
step = cmp.StepColormap(
[(255,183,183), (255,101,101), (255,40,40), (192,0,0), (169,0,0), (144,0,0), (107,1,1)],
vmin=25000, vmax=4000000,
index=[50000, 250000, 1000000, 2500000, 3000000, 3500000, 4000000], #for change in the colors, not used fr linear
caption='Color Scale for Map' #Caption for Color scale or Legend
)
step
Out[ ]:
In [ ]:
map = folium.Map(location=[53.0000, 9.0000], tiles = 'cartodbpositron', zoom_start=4)
Choropleth(geo_data=df_borders_boun.__geo_interface__, data=plot_dict, key_on='feature.id', fill_color='YlOrRd', legend_name='asd').add_to(map)
map
Out[ ]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]:
from geopy.geocoders import Nominatim
import numpy as np
In [ ]:
geolocator = Nominatim(user_agent='kaggle_learn') #turkey eklemeyi unutma, yanlış gösteren yerler var!!!!!
def my_geocoder(row):
try:
point = geolocator.geocode(row).point
return pd.Series({'Latitude': point.latitude, 'Longitude': point.longitude})
except:
return None
df_borders_w[['Latitude', 'Longitude']] = df_borders_w.apply(lambda x: my_geocoder(x['NAME']), axis=1)
print("{}% of addresses were geocoded!".format(
(1 - sum(np.isnan(df_borders_w["Latitude"])) / len(df_borders_w)) * 100))
data = df_borders_w.loc[~np.isnan(df_borders_w["Latitude"])]
data = gpd.GeoDataFrame(
data, geometry=gpd.points_from_xy(df_borders_w.Longitude, df_borders_w.Latitude))
#data.crs = {'init': 'epsg:4326'}
data.head()
100.0% of addresses were geocoded!
Out[ ]:
NAME | ORGN_NAME | geometry | index | 2017 | wineProduction | Percentage | Latitude | Longitude | |
---|---|---|---|---|---|---|---|---|---|
1 | ITALY | Italia | POINT (12.67430 42.63843) | 9 | 7169750 | 4250000 | 59.276823 | 42.638426 | 12.674297 |
2 | SPAIN | España | POINT (-4.83798 39.32607) | 6 | 5387400 | 3248000 | 60.288822 | 39.326068 | -4.837979 |
0 | FRANCE | France | POINT (1.88833 46.60335) | 7 | 5011050 | 3641900 | 72.677383 | 46.603354 | 1.888334 |
4 | TURKEY | Türkiye | POINT (34.92497 38.95976) | 26 | 4200000 | 64400 | 1.533333 | 38.959759 | 34.924965 |
3 | ROMANIA | România | POINT (24.68592 45.98521) | 18 | 1063340 | 431700 | 40.598492 | 45.985213 | 24.685923 |
In [ ]:
wine = list(wine) #for döngüsünde kullanmak için
In [ ]:
#wine = sorted(wine)
In [ ]:
#wine[0], wine[2] = wine[2], wine[0] #wine'ın ait olduğu dataframe'i de alfabetik sıraya göre sıralayabilirdim ama bu yol daha kısa geldi.İPTAL
In [ ]:
#wine[0], wine[1] = wine[1], wine[0]
In [ ]:
map1 = folium.Map(location=[53.0000, 9.0000], tiles = 'cartodbpositron', zoom_start=4)
folium.GeoJson(
df_borders_boun,
style_function=lambda feature: {
'fillColor': step(plot_dict[feature['id']]),
'color': 'black', #border color for the color fills
'weight': 1, #how thick the border has to be
'dashArray': '1, 1',
"fillOpacity": .75 #dashed lines length,space between them
}
).add_to(map1)
step.add_to(map1) #adds colorscale or legend
for i in range(0, len(df_borders_boun)):
label = '{}, {}'.format(df_borders_w['ORGN_NAME'].iloc[i], wine[i])
folium.Marker([df_borders_w['Latitude'].iloc[i], df_borders_w['Longitude'].iloc[i]], popup=label, icon=folium.Icon(color="blue")).add_to(map1)
map1
Out[ ]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]:
df_borders_w
Out[ ]:
NAME | ORGN_NAME | geometry | index | 2017 | wineProduction | Percentage | Latitude | Longitude | |
---|---|---|---|---|---|---|---|---|---|
1 | ITALY | Italia | MULTIPOLYGON (((12.46117 37.88075, 12.45686 37... | 9 | 7169750 | 4250000 | 59.276823 | 42.638426 | 12.674297 |
2 | SPAIN | España | MULTIPOLYGON (((-5.60904 36.00032, -5.61149 36... | 6 | 5387400 | 3248000 | 60.288822 | 39.326068 | -4.837979 |
0 | FRANCE | France | MULTIPOLYGON (((-2.28137 46.68570, -2.31121 46... | 7 | 5011050 | 3641900 | 72.677383 | 46.603354 | 1.888334 |
4 | TURKEY | Türkiye | MULTIPOLYGON (((29.11932 40.83066, 29.11734 40... | 26 | 4200000 | 64400 | 1.533333 | 38.959759 | 34.924965 |
3 | ROMANIA | România | MULTIPOLYGON (((29.59458 44.81385, 29.57739 44... | 18 | 1063340 | 431700 | 40.598492 | 45.985213 | 24.685923 |
In [ ]:
df_borders_w = df_borders_w.set_index('NAME') #plot_dict id'si için yaptım.
In [ ]:
plot_dict2 = df_borders_w['Percentage']
In [ ]:
plot_dict2
Out[ ]:
NAME ITALY 59.276823 SPAIN 60.288822 FRANCE 72.677383 TURKEY 1.533333 ROMANIA 40.598492 Name: Percentage, dtype: float64
In [ ]:
percentage = list(percentage)
In [ ]:
step2 = cmp.StepColormap(
[(255,183,183), (255,101,101), (255,40,40), (223,0,0), (192,0,0), (169,0,0), (144,0,0), (107,1,1)],
vmin=2, vmax=73,
index=[2, 15, 30, 40, 50, 59, 72], #for change in the colors, not used fr linear
caption='Color Scale for Map' #Caption for Color scale or Legend
)
step2
Out[ ]:
In [ ]:
map2 = folium.Map(location=[53.0000, 9.0000], tiles = 'cartodbpositron', zoom_start=4)
folium.GeoJson(
df_borders_boun,
style_function=lambda feature: {
'fillColor': step2(plot_dict2[feature['id']]),
'color': 'black', #border color for the color fills
'weight': 1, #how thick the border has to be
'dashArray': '1, 1',
"fillOpacity": .75
}
).add_to(map2)
step2.add_to(map2)
for i in range(0, len(df_borders_boun)):
label = '{}, {}'.format(df_borders_w['ORGN_NAME'].iloc[i], percentage[i])
folium.Marker([df_borders_w['Latitude'].iloc[i], df_borders_w['Longitude'].iloc[i]], popup=label, icon=folium.Icon(color="blue")).add_to(map2)
map2
Out[ ]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]:
plot_dict3 = df_borders_w['2017']
In [ ]:
plot_dict3
Out[ ]:
NAME ITALY 7169750 SPAIN 5387400 FRANCE 5011050 TURKEY 4200000 ROMANIA 1063340 Name: 2017, dtype: int64
In [ ]:
step3 = cmp.StepColormap(
[(255,183,183), (255,101,101), (255,40,40), (223,0,0), (192,0,0), (169,0,0), (144,0,0), (107,1,1)],
vmin=1063340, vmax=7169750,
index=[250000, 750000, 1000000, 2500000, 3500000, 5000000, 6500000], #for change in the colors, not used fr linear
caption='Color Scale for Map' #Caption for Color scale or Legend
)
step3
Out[ ]:
In [ ]:
map3 = folium.Map(location=[53.0000, 9.0000], tiles = 'cartodbpositron', zoom_start=4)
folium.GeoJson(
df_borders_boun,
style_function=lambda feature: {
'fillColor': step3(plot_dict3[feature['id']]),
'color': 'black', #border color for the color fills
'weight': 1, #how thick the border has to be
'dashArray': '1, 1',
"fillOpacity": .75
}
).add_to(map3)
step3.add_to(map3)
for i in range(0, len(df_borders_boun)):
label = '{}, {}'.format(df_borders_w['ORGN_NAME'].iloc[i], grape[i])
folium.Marker([df_borders_w['Latitude'].iloc[i], df_borders_w['Longitude'].iloc[i]], popup=label, icon=folium.Icon(color="blue")).add_to(map3)
map3
Out[ ]:
Make this Notebook Trusted to load map: File -> Trust Notebook