Last active
May 20, 2020 10:02
-
-
Save LowriWilliams/edc3fd83d453259dd0801b2c7c2fc106 to your computer and use it in GitHub Desktop.
corona/map_data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 222, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>Country</th>\n", | |
" <th>Confirmed</th>\n", | |
" <th>Lat</th>\n", | |
" <th>Long</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>0</th>\n", | |
" <td>Australia</td>\n", | |
" <td>194</td>\n", | |
" <td>-27.000000</td>\n", | |
" <td>133.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>Belgium</td>\n", | |
" <td>8</td>\n", | |
" <td>50.833333</td>\n", | |
" <td>4.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>Brazil</td>\n", | |
" <td>0</td>\n", | |
" <td>-10.000000</td>\n", | |
" <td>-55.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>Cambodia</td>\n", | |
" <td>16</td>\n", | |
" <td>13.000000</td>\n", | |
" <td>105.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>Canada</td>\n", | |
" <td>73</td>\n", | |
" <td>60.000000</td>\n", | |
" <td>-95.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>China</td>\n", | |
" <td>372405</td>\n", | |
" <td>35.000000</td>\n", | |
" <td>105.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>Finland</td>\n", | |
" <td>14</td>\n", | |
" <td>64.000000</td>\n", | |
" <td>26.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>France</td>\n", | |
" <td>117</td>\n", | |
" <td>46.000000</td>\n", | |
" <td>2.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>Germany</td>\n", | |
" <td>156</td>\n", | |
" <td>51.000000</td>\n", | |
" <td>9.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>Hong Kong</td>\n", | |
" <td>349</td>\n", | |
" <td>22.267000</td>\n", | |
" <td>114.188000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>India</td>\n", | |
" <td>32</td>\n", | |
" <td>20.000000</td>\n", | |
" <td>77.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>Italy</td>\n", | |
" <td>31</td>\n", | |
" <td>42.833333</td>\n", | |
" <td>12.833333</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>Ivory Coast</td>\n", | |
" <td>0</td>\n", | |
" <td>8.000000</td>\n", | |
" <td>-5.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>13</th>\n", | |
" <td>Japan</td>\n", | |
" <td>338</td>\n", | |
" <td>36.000000</td>\n", | |
" <td>138.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>14</th>\n", | |
" <td>Macau</td>\n", | |
" <td>149</td>\n", | |
" <td>22.166667</td>\n", | |
" <td>113.550000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>15</th>\n", | |
" <td>Malaysia</td>\n", | |
" <td>181</td>\n", | |
" <td>2.500000</td>\n", | |
" <td>112.500000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>16</th>\n", | |
" <td>Mexico</td>\n", | |
" <td>0</td>\n", | |
" <td>23.000000</td>\n", | |
" <td>-102.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>17</th>\n", | |
" <td>Nepal</td>\n", | |
" <td>18</td>\n", | |
" <td>28.000000</td>\n", | |
" <td>84.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>18</th>\n", | |
" <td>Philippines</td>\n", | |
" <td>29</td>\n", | |
" <td>13.000000</td>\n", | |
" <td>122.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>19</th>\n", | |
" <td>Russia</td>\n", | |
" <td>24</td>\n", | |
" <td>60.000000</td>\n", | |
" <td>100.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>20</th>\n", | |
" <td>Singapore</td>\n", | |
" <td>398</td>\n", | |
" <td>1.366667</td>\n", | |
" <td>103.800000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>21</th>\n", | |
" <td>South Korea</td>\n", | |
" <td>273</td>\n", | |
" <td>37.000000</td>\n", | |
" <td>127.500000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>22</th>\n", | |
" <td>Spain</td>\n", | |
" <td>15</td>\n", | |
" <td>40.000000</td>\n", | |
" <td>-4.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>23</th>\n", | |
" <td>Sri Lanka</td>\n", | |
" <td>16</td>\n", | |
" <td>7.000000</td>\n", | |
" <td>81.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>24</th>\n", | |
" <td>Sweden</td>\n", | |
" <td>12</td>\n", | |
" <td>62.000000</td>\n", | |
" <td>15.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>25</th>\n", | |
" <td>Taiwan</td>\n", | |
" <td>206</td>\n", | |
" <td>23.500000</td>\n", | |
" <td>121.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>26</th>\n", | |
" <td>Thailand</td>\n", | |
" <td>380</td>\n", | |
" <td>15.000000</td>\n", | |
" <td>100.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>27</th>\n", | |
" <td>United Arab Emirates</td>\n", | |
" <td>76</td>\n", | |
" <td>24.000000</td>\n", | |
" <td>54.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>28</th>\n", | |
" <td>United Kingdom</td>\n", | |
" <td>39</td>\n", | |
" <td>54.000000</td>\n", | |
" <td>-2.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>29</th>\n", | |
" <td>United States</td>\n", | |
" <td>162</td>\n", | |
" <td>38.000000</td>\n", | |
" <td>-97.000000</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>30</th>\n", | |
" <td>Vietnam</td>\n", | |
" <td>130</td>\n", | |
" <td>16.166667</td>\n", | |
" <td>107.833333</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" Country Confirmed Lat Long\n", | |
"0 Australia 194 -27.000000 133.000000\n", | |
"1 Belgium 8 50.833333 4.000000\n", | |
"2 Brazil 0 -10.000000 -55.000000\n", | |
"3 Cambodia 16 13.000000 105.000000\n", | |
"4 Canada 73 60.000000 -95.000000\n", | |
"5 China 372405 35.000000 105.000000\n", | |
"6 Finland 14 64.000000 26.000000\n", | |
"7 France 117 46.000000 2.000000\n", | |
"8 Germany 156 51.000000 9.000000\n", | |
"9 Hong Kong 349 22.267000 114.188000\n", | |
"10 India 32 20.000000 77.000000\n", | |
"11 Italy 31 42.833333 12.833333\n", | |
"12 Ivory Coast 0 8.000000 -5.000000\n", | |
"13 Japan 338 36.000000 138.000000\n", | |
"14 Macau 149 22.166667 113.550000\n", | |
"15 Malaysia 181 2.500000 112.500000\n", | |
"16 Mexico 0 23.000000 -102.000000\n", | |
"17 Nepal 18 28.000000 84.000000\n", | |
"18 Philippines 29 13.000000 122.000000\n", | |
"19 Russia 24 60.000000 100.000000\n", | |
"20 Singapore 398 1.366667 103.800000\n", | |
"21 South Korea 273 37.000000 127.500000\n", | |
"22 Spain 15 40.000000 -4.000000\n", | |
"23 Sri Lanka 16 7.000000 81.000000\n", | |
"24 Sweden 12 62.000000 15.000000\n", | |
"25 Taiwan 206 23.500000 121.000000\n", | |
"26 Thailand 380 15.000000 100.000000\n", | |
"27 United Arab Emirates 76 24.000000 54.000000\n", | |
"28 United Kingdom 39 54.000000 -2.000000\n", | |
"29 United States 162 38.000000 -97.000000\n", | |
"30 Vietnam 130 16.166667 107.833333" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import json\n", | |
"import numpy as np\n", | |
"\n", | |
"# Renaming countries\n", | |
"\n", | |
"df['Country'].replace({'UK' : 'United Kingdom', 'US' : 'United States'}, inplace = True)\n", | |
"\n", | |
"# Open coordinates file \n", | |
"\n", | |
"coordinates = []\n", | |
"\n", | |
"with open('countries_lat_long.json') as json_file:\n", | |
" data = json.load(json_file)\n", | |
" \n", | |
"for i in data:\n", | |
" tmp = []\n", | |
" for k, v in i.items():\n", | |
" if k == 'name' or k == 'latlng': \n", | |
" tmp.append(v)\n", | |
" coordinates.append(tmp)\n", | |
"\n", | |
"# Mapping lat and long to countries with virus\n", | |
"\n", | |
"lat = []\n", | |
"long = []\n", | |
"\n", | |
"for i in df_country['Country'].values.tolist():\n", | |
" for c in coordinates:\n", | |
" if i == c[1]:\n", | |
" lat.append(c[0][0])\n", | |
" long.append(c[0][1])\n", | |
"\n", | |
"# Add coordinates to dataframe\n", | |
"\n", | |
"df_country['Lat'] = lat\n", | |
"df_country['Long'] = long\n", | |
"\n", | |
"display(df_country)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment