Guest User

Untitled

a guest
Dec 16th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. ad = t.arrdelay.mean().name('ad')
  2. dd = t.depdelay.mean().name('dd')
  3. flt_bet = t.count().name('fbp')
  4. origin = t.origin_city.name('origin')
  5. dest = t.dest_city.name('dest')
  6.  
  7. fbp_expr = t.group_by([origin, dest]).aggregate(flt_bet)
  8. #print(fbp_expr.compile())
  9.  
  10. expr = t\
  11. .group_by(['origin_city','dest_city'])\
  12. .having([ad.notnull(), dd.notnull(), ad > 10, dd > 10])\
  13. .aggregate([ad,dd])
  14.  
  15. #print(expr.compile())
  16.  
  17. fc = fbp_expr.view()
  18.  
  19. #Create a join expr - for all pairs of cities with at least 5000 flights between the pair,
  20. #find where there were at least an average delay of 10 mins for both arrival and departure
  21. join_expr = fc[(fc.fbp > 5000) ]\
  22. .inner_join(expr,[(fc.origin == expr.origin_city),(fc.dest == expr.dest_city)])[expr, fc.fbp]\
  23. .sort_by([('ad',False),('dd',False)]).limit(100)
  24.  
  25. #print(join_expr.compile())
  26.  
  27. delay_pairs_chart = alt.Chart(join_expr).mark_circle().encode(
  28. alt.X(alt.repeat("column"), type='quantitative'),
  29. alt.Y(alt.repeat("row"), type='quantitative'),
  30. color='fbp:N'
  31. ).properties(
  32. width=150,
  33. height=150
  34. ).repeat(
  35. row=['dd', 'ad', 'fbp'],
  36. column=['dd', 'ad', 'fbp']
  37. ).interactive()
Add Comment
Please, Sign In to add comment