Este análisis es de que cuantas personas ingresan a una atracción en un rango de tiempo especifico.
Importar Librerias
In [2]:
import pandas as pd
%matplotlib inline
import seaborn as sns
from matplotlib import pyplot as plt
import numpy as np
sns.set_style("darkgrid")
Lectura de Datos
In [3]:
cd /Users/Sebastian/Google\ Drive/Uniandes/Visual\ Analytics/Mini_chalange1/MC1\ 2015\ Data/
In [4]:
data = pd.read_csv("park-movement-Fri.csv")
Transformar los datos de tiempo
In [5]:
data["time"] = pd.to_datetime(data.Timestamp, format="%Y-%m-%d %H:%M:%S")
Identificar checkins
In [6]:
checkins = data.loc[data["type"]=="check-in"]
In [40]:
movements = data.loc[data["type"]=="movement"]
Establecer un rango de tiempo
In [86]:
time = (checkins["time"] >= '2014-06-06 08:00:00') & (checkins["time"] <= '2014-06-06 23:59:59')
Buscar datos checkins en el rango
In [87]:
checkins_by_time = checkins.loc[time]
Crear una clase para trabajar con cada atracción
In [88]:
class Atraccion(object):
def __init__(self,X,Y,Visitors):
self.X = X
self.Y = Y
self.Visitors = Visitors
self.Visits = Visitors["id"].count()
self.Wait_Time = 0
Llenar los objetos de Atracción
In [89]:
checkins_by_range = checkins_by_time.groupby(['X', 'Y'])
Atracciones = []
for key,group in checkins_by_range:
Atracciones.append(Atraccion(key[0],key[1],group))
In [95]:
for atrac in Atracciones:
wt=0
print "Atraccion"
for index, per in atrac.Visitors.iterrows():
t_i = per["time"]
t_f = movements.loc[(movements["id"] == per["id"]) & (movements["time"] >t_i)]["time"].min()
t_w = (t_f - t_i) / np.timedelta64(1,'m')
wt = wt + t_w
atrac.Wait_Time = wt / atrac.Visits
In [93]:
for Atr in Atracciones:
print str("X: ")+str(Atr.X)
print str("Y: ")+str(Atr.Y)
print str("Visitantes: ")+str(Atr.Visits)
print str("Tiempo de espera: ")+str(Atr.Wait_Time)
In [91]:
len(Atracciones)
Out[91]:
In [ ]: