In [6]:
import json
import urllib.request as request

In [83]:
url = 'https://restcountries.eu/rest/v1/all/'

In [84]:
content = request.urlopen(url).read()

In [85]:
data = json.loads(content.decode('utf-8'))

In [86]:
array = []
for country in data:
    array.append(country['region'])

In [87]:
import numpy as np
from scipy import stats

In [88]:
stats.mode(array)


/home/lmayra/.pyenv/versions/3.4.3/lib/python3.4/site-packages/scipy/stats/stats.py:257: RuntimeWarning: The input array could not be properly checked for nan values. nan values will be ignored.
  "values. nan values will be ignored.", RuntimeWarning)
Out[88]:
ModeResult(mode=array(['Africa'], 
      dtype='<U8'), count=array([59]))

In [89]:
array_np = np.array(array)

In [90]:
frequency = stats.itemfreq(array)

In [91]:
print(frequency)


[['' '3']
 ['Africa' '59']
 ['Americas' '56']
 ['Asia' '50']
 ['Europe' '52']
 ['Oceania' '27']]

In [92]:
xi = frequency[:, 0]
print(xi)


['' 'Africa' 'Americas' 'Asia' 'Europe' 'Oceania']

In [93]:
fi = frequency[:, 1].astype(int)
print(fi)


[ 3 59 56 50 52 27]

In [94]:
%matplotlib notebook
import matplotlib.pyplot as plt

x_pos = np.arange(len(xi))
plt.figure(1)
plt.bar(x_pos, fi, align='center')
plt.ylim(0, max(fi) + 10)
plt.xticks(np.arange(len(xi)), xi)
plt.show()