In [77]:
import plotly
import plotly.plotly as py
from plotly.graph_objs import *
import pandas as pd
import math
from IPython.display import Image
import time

plotly.tools.set_credentials_file(username='xjiang36', api_key='uZyWsdSH3xd9bxUefIFf')

In [78]:
dfroutes = pd.read_csv("routes.txt",encoding='iso-8859-1')
dftrips = pd.read_csv("trips.txt",encoding='iso-8859-1')
routeclean=dftrips["route_id"].value_counts().reset_index().rename(columns={'index': 'x'})
def Nameclean(dataset,a):
    wordlist=["SILVER","ILLINI","TEAL","YELLOW","GREEN","BROWN","GREY","GOLD","LIME","BLUE","RED","BROWN","BRONZE","ORANGE","LAVENDER","RUBY"]
    for j in range(len(wordlist)):
        for i in range(len(dataset)):
            if dataset[a][i].find(wordlist[j])>=0:
                dataset[a][i]=wordlist[j]
Nameclean(routeclean,"x")
sumroute=routeclean[:18]
cleanedroute=routeclean["x"].value_counts().reset_index().rename(columns={'index': 'name'})
for j in range(len(cleanedroute["name"])):
    rsum=0
    for i in range(len(routeclean)):
        if routeclean["x"][i]==cleanedroute["name"][j]:
            rsum+=routeclean["route_id"][i]
    cleanedroute["x"][j]=rsum
colorbar0=[]
for i in range(len(cleanedroute['name'])):
    for j in range(len(dfroutes['route_id'])):
        if cleanedroute['name'][i]==dfroutes['route_id'][j]:
            colorbar0.append("#%s"%dfroutes['route_color'][j])
            break
import plotly.plotly as py
import plotly.graph_objs as go

trace0 = go.Bar(
    x=cleanedroute["name"],
    y=cleanedroute["x"],
    marker=dict(
        #color=['#66FF66','#FFFF66','#E0E0E0','','#666600','#A0A0A0','#FF6666','#B266FF','#CCCC00','#663300','#FFFF99','#FF9933','#FF0000','#66FFFF','#0000FF','#FF66B2','#000066','#330000']),
        color=colorbar0),
)

data = [trace0]
layout = go.Layout(
    title='Buses on each route',
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='color-bar')


/opt/conda/lib/python3.5/site-packages/ipykernel/__main__.py:9: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

/opt/conda/lib/python3.5/site-packages/ipykernel/__main__.py:18: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

Out[78]:

In [79]:
dfroutes = pd.read_csv("routes.txt",encoding='iso-8859-1')
dftrips = pd.read_csv("trips.txt",encoding='iso-8859-1')
routeclean=dftrips["route_id"].value_counts().reset_index().rename(columns={'index': 'x'})
def Nameclean(dataset,a):
    wordlist=["SILVER","ILLINI","TEAL","YELLOW","GREEN","BROWN","GREY","GOLD","LIME","BLUE","RED","BROWN","BRONZE","ORANGE","LAVENDER","RUBY"]
    for j in range(len(wordlist)):
        for i in range(len(dataset)):
            if dataset[a][i].find(wordlist[j])>=0:
                dataset[a][i]=wordlist[j]
Nameclean(routeclean,"x")
sumroute=routeclean[:18]
cleanedroute=routeclean["x"].value_counts().reset_index().rename(columns={'index': 'name'})
trace0 = go.Bar(
    x=cleanedroute["name"],
    y=cleanedroute["x"],
    marker=dict(
        #color=['#66FF66','#FFFF66','#E0E0E0','','#666600','#A0A0A0','#FF6666','#B266FF','#CCCC00','#663300','#FFFF99','#FF9933','#FF0000','#66FFFF','#0000FF','#FF66B2','#000066','#330000']),
        color=colorbar0),
)

data = [trace0]
layout = go.Layout(
    title='Distribution of each route by color',
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='color-bar')


/opt/conda/lib/python3.5/site-packages/ipykernel/__main__.py:9: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

Out[79]:

In [ ]: