예제 #1
0
def foo():
    # Cargamos los datos
    datos1 = sci.load_xl("Libro1.xlsx", "Hoja1", "D4:D10")
    datos2 = sci.load_xl("Libro1.xlsx", "Hoja1", "E4:E10")

    w = 0.8 / 2

    x1 = [1, 2, 3, 4]
    x2 = [1 + w, 2 + w, 3 + w, 4 + w]

    c0_20_1 = len(sci.data_filter(datos1, lambda dic: dic["Edad"] <= 20))
    c21_40_1 = len(sci.data_filter(datos1, lambda dic: dic["Edad"] > 20 and dic["Edad"] <= 40))
    c41_60_1 = len(sci.data_filter(datos1, lambda dic: dic["Edad"] > 40 and dic["Edad"] <= 60))
    c61_x_1 = len(sci.data_filter(datos1, lambda dic: dic["Edad"] > 60))
    
    c0_20_2 = len(sci.data_filter(datos2, lambda dic: dic["Edad"] <= 20))
    c21_40_2 = len(sci.data_filter(datos2, lambda dic: dic["Edad"] > 20 and dic["Edad"] <= 40))
    c41_60_2 = len(sci.data_filter(datos2, lambda dic: dic["Edad"] > 40 and dic["Edad"] <= 60))
    c61_x_2 = len(sci.data_filter(datos2, lambda dic: dic["Edad"] > 60))

    y1 = [c0_20_1, c21_40_1, c41_60_1, c61_x_1]
    y2 = [c0_20_2, c21_40_2, c41_60_2, c61_x_2]

    fig, ax = plt.subplots()

    ax.bar(x1, y1, w) #
    ax.bar(x2, y2, w) #

    # Regresamos la imagen como la respuesta del servidor
    canvas = FigureCanvasAgg(fig)

    png_output = StringIO.StringIO()

    canvas.print_png(png_output)

    response = make_response(png_output.getvalue())

    response.headers["Content-Type"] = "image/png"

    return response
예제 #2
0
def home():
    datos = sci.load_xl("Libro1.xlsx", "Hoja1", "C4:F10")

    labels = sci.data_map(datos[0], lambda k: k)

    html = "<table>"

    html += "<tr>"
    for label in labels:
        html += "<th>%s</th>" % label
    html += "</tr>"

    for dic in datos:
        html += "<tr>"
        for label in labels:
            html += "<td>%s</td>" % (str(dic[label]))
        html += "</tr>"

    html += "</table>"

    return html
예제 #3
0
def foo():
    # Cargamos los datos
    datos = sci.load_xl("Libro1.xlsx", "Hoja1", "E4:E10")

    # Cargamos las categorias de Sexo
    categorias = sci.cat_set_build(datos, ["Sexo"])[0]

    # Calculamos los totales
    total = {}

    for cat in categorias:
        total[cat] = len(sci.data_filter(datos,
            lambda dic: dic["Sexo"] == cat))

    # Calculamos los totales por categoria
    sizes = [total[cat] for cat in categorias]
    labels = categorias

    # Dibujamos el pastel
    fig, ax1 = plt.subplots()
    ax1.pie(sizes, labels=labels, autopct='%1.1f%%',
            shadow=True, startangle=90)
    ax1.axis('equal')

    # Regresamos la imagen como la respuesta del servidor
    canvas = FigureCanvasAgg(fig)

    png_output = StringIO.StringIO()

    canvas.print_png(png_output)

    response = make_response(png_output.getvalue())

    response.headers["Content-Type"] = "image/png"

    return response
예제 #4
0
from sci import load_xl, data_map

datos = load_xl("datos_flujo.xlsx", "Hoja1", "B2:D9")

def f(dic):
    # dic (N, S, A)
    if dic["S"] > 5:
        return dic

filtrados = data_map(datos, f)

print filtrados
예제 #5
0

def latlon(coord):
    #22°21′00″N
    r = re.search("(\d+).(\d+).(\d+)..(\w)", coord)

    g = int(r.group(1))
    m = int(r.group(2))
    s = int(r.group(3))

    return g + m / 60.0 + s / 3600.0


import sci

estados = sci.load_xl("estados.xlsx", "Hoja1", "A1:E101")

for ciudad in estados:
    nombre_estado = ciudad["Estado"]
    nombre_ciudad = ciudad["Ciudad"]

    latitud = ciudad["Latitud"]
    longitud = ciudad["Longitud"]

    lat = latlon(latitud)
    lon = -latlon(longitud)

    x, y = map(lon, lat)

    plt.plot(x, y, "ko")
예제 #6
0
import re

def latlon(coord):
    #22°21′00″N
    r = re.search("(\d+).(\d+).(\d+)..(\w)", coord)

    g = int(r.group(1))
    m = int(r.group(2))
    s = int(r.group(3))

    return g + m / 60.0 + s / 3600.0

import sci

rutas = sci.load_xl("estados.xlsx", "Hoja2", "A1:C9")

X = []
Y = []

for ruta in rutas:
    latitud = ruta["Latitud"] 
    longitud = ruta["Longitud"]

    lat = latlon(latitud)
    lon = -latlon(longitud)

    x, y = map(lon, lat)

    X.append(x)
    Y.append(y)
예제 #7
0
from sci import load_xl, data_map
from datetime import datetime

clientes = load_xl("clientes.xlsx", "Hoja1", "A1:C1001")


def enero_2015(cliente):
    # cliente (Nombre, Fecha, Consumo)
    fecha = datetime.strptime(cliente["Fecha"], "%d-%m-%Y")
    ini = datetime.strptime("1-1-2015", "%d-%m-%Y")
    fin = datetime.strptime("31-1-2015", "%d-%m-%Y")

    if fecha >= ini and fecha <= fin:
        return cliente["Consumo"]


consumos = data_map(clientes, enero_2015)

total = sum(consumos)
promedio = total / len(consumos)

print "Total de consumo: %d Promedio: %.2f" % (total, promedio)
예제 #8
0
from sci import load_xl

enero = load_xl("ejercicio_1.xlsx", "Hoja 1", "B4:D8")
febrero = load_xl("ejercicio_1.xlsx", "Hoja 1", "B11:D15")
marzo = load_xl("ejercicio_1.xlsx", "Hoja 1", "B18:D22")

def ingresos(lista, nombre):
	for persona in lista:
		# persona (Nombre, Ingresos, Gastos)
		if persona["Nombre"] == nombre:
			return persona["Ingresos"]

def gastos(lista, nombre):
	for persona in lista:
		# persona (Nombre, Ingresos, Gastos)
		if persona["Nombre"] == nombre:
			return persona["Gastos"]

def nombres(lista):
	aux = []
	for persona in lista:
		aux.append(persona["Nombre"])
	return aux

total = []

for nombre in nombres(enero):
	persona = {
		"Nombre": nombre
	}
예제 #9
0
import sci

datos = sci.load_xl("sintomas.xlsx", "Hoja1", "B3:G8")

def tdatoX(paciente):
    sexo = 1 if paciente["Sexo"] == "Hombre" else 2

    s1 = 1 if paciente["S1"] == "SI" else 0
    s2 = 1 if paciente["S2"] == "SI" else 0
    s3 = 1 if paciente["S3"] == "SI" else 0

    return [sexo, s1, s2, s3]

def tdatoY(paciente):
    e1 = 1 if paciente["E1"] == "SI" else 0
    e2 = 1 if paciente["E2"] == "SI" else 0

    return [e1, e2]

X = sci.data_map(datos, tdatoX)
Y = sci.data_map(datos, tdatoY)

from sklearn.neural_network import MLPClassifier

clf = MLPClassifier()

clf.fit(X, Y)

Yp = clf.predict([[1, 1, 0, 1], [0, 0, 0, 1]])

def f(Y):
예제 #10
0
from sci import load_xl, data_map, data_filter

datos = load_xl("Libro1.xlsx", "Datos", "A1:D102")

def es_hombre(dic):
    if dic["Sexo"] == "Hombre":
        return True

def es_mujer(dic):
    if dic["Sexo"] == "Mujer":
        return True

def es_otro(dic):
    if dic["Sexo"] == "Indefinido":
        return True

hombres = data_filter(datos, es_hombre)
mujeres = data_filter(datos, es_mujer)
otros = data_filter(datos, es_otro)

H = len(hombres)
M = len(mujeres)
O = len(otros)

import matplotlib.pyplot as plt

# Pie chart, where the slices will be ordered and plotted counter-clockwise:
labels = ['Hombre', 'Mujer', "Indefinido"]
sizes = [H, M, O]
explode = [0, 0, 0.4]  # only "explode" the 2nd slice (i.e. 'Hogs')
예제 #11
0
def datos(nombre, hoja, rango):
    data = sci.load_xl("%s.xlsx" % nombre, hoja, rango)
    return json.dumps(data)
예제 #12
0
filename = "sintomas.xlsx"
sheet_name = "Hoja1"
cell_range = "B3:G8"

xlabels = ["Sexo", "S1", "S2", "S3"]
ylabels = ["E1", "E2"]

tests = [
    [0, 0, 0, 0]
]

###############################################################

# 1. Cargar los datos de analisis desde excel
datos = sci.load_xl(filename, sheet_name, cell_range)

# 2. recuperar las matrices de analisis
X, Y = sci.data_analize(datos, xlabels, ylabels)

# 3. Detectar las categorias automaticamente
xcats = sci.cat_set_build(datos, xlabels)
ycats = sci.cat_set_build(datos, ylabels)

print "Categorias X: %s" %str(xcats)
print "Categorias Y: %s" %str(ycats)

# 4. Transformar los datos por categoria
Xp = sci.cat_transform(X, xcats)
Yp = sci.cat_transform(Y, ycats)