<jupyter_start><jupyter_text>Choropleth Map for International Sales In this section we will create a choropleth map to show the amount of value that was brought by foreign countries. Since github renders this notebook as static html, you can use the link below to open this notebook with nbviewer in order to see the choropleth map.[(View Choropleth Map)](https://nbviewer.jupyter.org/github/amir-hojjati/Data-Analysis-Online-Retail-Transactions/blob/4ee5e2d6860acfb68d0cfeecda53a31751e599db/Data-Visualization/2-Choropleth-Map.ipynb)In this choropleth map we have the map of the world and the total value from customers of each country is shown with the color scale. Since we would need the country code for each country, we used the pycountry library to get the codes from the column 'Country'.<jupyter_code>#importing necessary libraries
import pandas as pd, numpy as np, matplotlib.pyplot as plt
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.plotly as py, plotly.graph_objs as go
import cufflinks as cf
import pycountry
from pycountry_convert import country_name_to_country_alpha3
init_notebook_mode(connected=True)
%matplotlib inline

#importing dataset
CleanDataset = r'../Cleaned-Dataset/OnlineRetail_Cleaned.csv'
Data_Cleaned = pd.read_csv(CleanDataset, index_col = 'InvoiceDate')
Data_Cleaned.index = pd.to_datetime(Data_Cleaned.index, format = '%Y-%m-%d %H:%M', box = False)

#function to get country codes from country names
def code(x):
    try:
        return country_name_to_country_alpha3(x,cn_name_format='upper')
    except:
        pass
Data_Cleaned['CountryCode'] = Data_Cleaned['Country'].map(code)

#creating the choropleth map
mapdata = Data_Cleaned.dropna()
map_data = {
    'type': 'choropleth',
    'autocolorscale' : False,
    'colorscale' : 'Portland',
    'locations' : mapdata[mapdata['CountryCode']!='GBR'].groupby('CountryCode', sort=False)['FinalPrice'].sum().index,
    'z' : mapdata[mapdata['CountryCode']!='GBR'].groupby('CountryCode', sort=False)['FinalPrice'].sum().values,
    'text' :  mapdata[mapdata['CountryCode']!='GBR']['Country'].unique(),
    'colorbar' : {'title':'Pounds'}
}
map_layout = {
    'title' : 'Sales in Foreign Countries',
    'geo' : {'showframe' : False, 'projection' : {'type':'equirectangular'}}
}
FinalMap = go.Figure(data = [map_data], layout = map_layout)
iplot(FinalMap)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11350455675227837, 'fraction_numerical': 0.009527754763877383, 'mean_word_length': 5.802816901408451, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '444415', 'license': 'MIT', 'n_tokens_mistral': 796, 'n_tokens_neox': 772, 'n_words': 214, 'path': 'Data-Visualization/2-Choropleth-Map.ipynb', 'repo_name': 'tahmidbintaslim/Data-Analysis-Online-Retail-Transactions', 'size': '2414'}