Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #amount of trains in each station
  2. from plotly.offline import plot
  3. from plotly.graph_objs import *
  4. x = trips.toPandas()['trip_headsign']
  5. data = Data([Histogram(x=x)])
  6. p = plot(data, filename = 'basic_histogram', output_type = 'div')
  7. displayHTML(p)
  8.  
  9.  
  10.  
  11. # Graph of amount of stops for each train route
  12. from plotly.offline import plot
  13. from plotly.graph_objs import *
  14.  
  15. # Create random data with numpy
  16. import numpy as np
  17.  
  18. # Create a trace
  19. trace = go.Scatter(x = lineinfo.toPandas()['vehicle_id'], y = lineinfo.toPandas()['nr_of_stops'],mode = 'markers')
  20.  
  21. data = [trace]
  22.  
  23. # Plot and embed in ipython notebook!
  24. p = plot(data, filename = 'basic_histogram', output_type = 'div')
  25. displayHTML(p)
  26.  
  27. #graph of arrival delays per station (boxplot)
  28. from plotly.offline import plot
  29. import plotly.graph_objs as go
  30. X = trip_updates.toPandas()['arrival_delay'] / 60
  31. data = [go.Box(y = X, x =trip_updates.toPandas()['label'])]
  32. p = plot(data, filename='Boxplots_arrival_delay',output_type='div', validate = False)
  33. displayHTML(p)
  34.  
  35. # graph of departure delays per station (boxplot)
  36. from plotly.offline import plot
  37. import plotly.graph_objs as go
  38. X = trip_updates.toPandas()['departure_delay'] / 60
  39. data = [go.Box(y = X, x =trip_updates.toPandas()['label'])]
  40. p = plot(data, filename='Boxplots_departure_delay',output_type='div', validate = False)
  41. displayHTML(p)
  42. # graph of arrival delays per train type
  43. from pyspark.sql.functions import udf
  44. from pyspark.sql.types import StringType, FloatType, IntegerType
  45. import re
  46. import time
  47. from plotly.offline import plot
  48. import plotly.graph_objs as go
  49. trainType = udf(lambda x: re.findall("[a-zA-Z]+", x)[0], StringType())
  50. trip_updates = trip_updates.withColumn('train_type', trainType("id"))
  51.  
  52. X = trip_updates.toPandas()['arrival_delay'] / 60
  53. data = [go.Box(y = X, x =trip_updates.toPandas()['train_type'])]
  54. p = plot(data, filename='Boxplots_arrival_delay',output_type='div', validate = False)
  55. displayHTML(p)
  56. # Boxplot of train delays per train type
  57. X = trip_updates.toPandas()['departure_delay'] / 60
  58. data = [go.Box(y = X, x =trip_updates.toPandas()['train_type'])]
  59. p = plot(data, filename='Boxplots_arrival_delay',output_type='div', validate = False)
  60. displayHTML(p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement