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

In [2]:
import urllib.request as request
file = request.urlopen('https://raw.githubusercontent.com/lidimayra/basic-stats/master/frequencies/pokemons.txt')
print(file)


<http.client.HTTPResponse object at 0x7fc272070358>

In [3]:
pokemons = file.read().decode('UTF-8')

In [4]:
file.close()

In [5]:
print(pokemons)


Pidgeotto
Pidgey
Pidgey
Pidgey
Pidgey
Pidgey
Poliwag
Rapidash
Rattata
Rattata
Sandshrew
Sandshrew

In [6]:
pokemons_list = pokemons.split()

In [7]:
pokemons_list[6]


Out[7]:
'Poliwag'

In [8]:
pokemons_list[7]


Out[8]:
'Rapidash'

In [9]:
pokemons_list[8]


Out[9]:
'Rattata'

In [10]:
stats.mode(pokemons_list)[1]


/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[10]:
array([5])

In [11]:
frequencies = stats.itemfreq(pokemons_list)
print(frequencies)


[['Pidgeotto' '1']
 ['Pidgey' '5']
 ['Poliwag' '1']
 ['Rapidash' '1']
 ['Rattata' '2']
 ['Sandshrew' '2']]

In [12]:
type(frequencies)


Out[12]:
numpy.ndarray

In [35]:
xi = frequencies[:, 0]
print(xi)


['Pidgeotto' 'Pidgey' 'Poliwag' 'Rapidash' 'Rattata' 'Sandshrew']

In [36]:
fi = frequencies[:, 1]
print(fi)


['1' '5' '1' '1' '2' '2']

In [37]:
fi = fi.astype(int)
print(fi)


[1 5 1 1 2 2]

In [38]:
np.arange(10)


Out[38]:
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

In [39]:
len(xi)


Out[39]:
6

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

size = len(xi)
x_location = np.arange(size)
plt.bar(x_location, fi, align='center')


Out[82]:
<Container object of 6 artists>

In [29]:
size = len(xi)
print(size)


6

In [33]:
x_location = np.arange(size)
print(x_location)


[0 1 2 3 4 5]

In [83]:
plt.xticks(np.arange(size), xi)


Out[83]:
([<matplotlib.axis.XTick at 0x7fc26cffd400>,
  <matplotlib.axis.XTick at 0x7fc26d056f28>,
  <matplotlib.axis.XTick at 0x7fc26cf4b7f0>,
  <matplotlib.axis.XTick at 0x7fc26d1752b0>,
  <matplotlib.axis.XTick at 0x7fc26d206b00>,
  <matplotlib.axis.XTick at 0x7fc26d1f4b00>],
 <a list of 6 Text xticklabel objects>)

In [84]:
plt.ylim(0, max(fi) + 0.5)


Out[84]:
(0, 5.5)

In [ ]: