Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. oscar_data = [
  2. ["The Shape of Water", 2017, 6.914, 123, ['sci-fi', 'drama'], 19.4, 195.243464],
  3. ["Moonlight", 2016, 6.151, 110, ['drama'], 1.5, 65.046687],
  4. ["Spotlight", 2015, 7.489, 129, ['drama', 'crime', 'history'], 20.0, 88.346473],
  5. ["Birdman", 2014, 7.604, 119, ['drama', 'comedy'], 18.0, 103.215094],
  6. ["12 Years a Slave", 2013, 7.71, 133, ['drama', 'biography', 'history'], 20.0, 178.371993],
  7. ["Argo", 2012, 7.517, 120, ['thriller', 'drama', 'biography'], 44.5, 232.324128],
  8. ["The Artist", 2011, 7.942, 96, ['drama', 'melodrama', 'comedy'], 15.0, 133.432856],
  9. ["The King\'s Speech", 2010, 7.977, 118, ['drama', 'biography', 'history'], 15.0, 414.211549],
  10. ["The Hurt Locker", 2008, 7.298, 126, ['thriller', 'drama', 'war', 'history'], 15.0, 49.230772],
  11. ["Slumdog Millionaire", 2008, 7.724, 120, ['drama', 'melodrama'], 15.0, 377.910544],
  12. ["No Country for Old Men", 2007, 7.726, 122, ['thriller', 'drama', 'crime'], 25.0, 171.627166],
  13. ["The Departed", 2006, 8.456, 151, ['thriller', 'drama', 'crime'], 90.0, 289.847354],
  14. ["Crash", 2004, 7.896, 108, ['thriller', 'drama', 'crime'], 6.5, 98.410061],
  15. ["Million Dollar Baby", 2004, 8.075, 132, ['drama', 'sport'], 30.0, 216.763646],
  16. ["The Lord of the Rings: Return of the King", 2003, 8.617, 201, ['fantasy', 'drama', 'adventure'], 94.0, 1119.110941],
  17. ["Chicago", 2002, 7.669, 113, ['musical', 'comedy', 'crime'], 45.0, 306.776732],
  18. ['A Beautiful Mind', 2001, 8.557, 135, ['drama', 'biography', 'melodrama'], 58.0, 313.542341],
  19. ["Gladiator", 2000, 8.585, 155, ['action', 'drama', 'adventure'], 103.0, 457.640427],
  20. ["American Beauty", 1999, 7.965, 122, ['drama'], 15.0, 356.296601],
  21. ["Shakespeare in Love", 1998, 7.452, 123, ['drama', 'melodrama', 'comedy', 'history'], 25.0, 289.317794],
  22. ["Titanic", 1997, 8.369, 194, ['drama', 'melodrama'], 200.0, 2185.372302],
  23. ["The English Patient", 1996, 7.849, 155, ['drama', 'melodrama', 'war'], 27.0, 231.976425],
  24. ["Braveheart", 1995, 8.283, 178, ['drama', 'war', 'biography', 'history'], 72.0, 210.409945],
  25. ["Forrest Gump", 1994, 8.915, 142, ['drama', 'melodrama'], 55.0, 677.386686],
  26. ["Schindler\'s List", 1993, 8.819, 195, ['drama', 'biography', 'history'], 22.0, 321.265768],
  27. ["Unforgiven", 1992, 7.858, 131, ['drama', 'western'], 14.4, 159.157447],
  28. ["Silence of the Lambs", 1990, 8.335, 114, ['thriller', 'crime', 'mystery', 'drama', 'horror'], 19.0, 272.742922],
  29. ["Dances with Wolves", 1990, 8.112, 181, ['drama', 'adventure', 'western'], 22.0, 424.208848],
  30. ["Driving Miss Daisy", 1989, 7.645, 99, ['drama'], 7.5, 145.793296],
  31. ["Rain Man", 1988, 8.25, 133, ['drama'], 25.0, 354.825435],
  32. ]
  33.  
  34. def filter_by_genre(data, genre):
  35. result = []
  36. for row in data:
  37. genres = row[4]
  38. if genre in genres:
  39. result.append(row)
  40. return result
  41.  
  42. def column_sum(data, column):
  43. result = 0
  44. for row in data:
  45. result += row[column]
  46. return result
  47.  
  48. def column_mean(data, column):
  49. total = column_sum(data, column)
  50. mean = total / len(data)
  51. return mean
  52.  
  53. def add_roi(data):
  54. for i in range(len(data)):
  55. budget = data[i][5]
  56. gross = data[i][6]
  57. roi = (gross - budget) / budget
  58. data[i].append(roi)
  59.  
  60. def add_cost_per_minute(data):
  61. for i in range(len(data)):
  62. length = data[i][3]
  63. budget = data[i][5]
  64. price_per_minute = budget / length
  65. data[i].append(price_per_minute)
  66.  
  67. # the variable with the selected genres
  68. selected_genres = ['history', 'melodrama', 'crime', 'biography', 'thriller']
  69.  
  70. # add columns for the ROI and cost per minute of film to the table
  71. # to do this, use the functions add_roi() and add_cost_per_minute
  72. add_roi(oscar_data)
  73. add_cost_per_minute(oscar_data)
  74.  
  75. genres_means = []
  76. for genre in selected_genres:
  77. filt_data = filter_by_genre(oscar_data, genre)
  78. # < write code here >
  79.  
  80. # calculate the filtered table's means
  81.  
  82. # mean score (index column 2)
  83. mean_score = column_mean(filt_data, 2)
  84.  
  85. # mean length (index column 3)
  86. mean_length = column_mean(filt_data, 3)
  87.  
  88. # mean ROI value (index column 7)
  89. mean_roi = column_mean(filt_data, 7)
  90.  
  91. #average cost per minute (index column 8)
  92. mean_cpm = column_mean(filt_data, 8)
  93.  
  94. genres_means.append([genre, mean_score, mean_length, mean_roi, mean_cpm])
  95.  
  96. print('Genre | Rating | Length | ROI | Cost per minute')
  97. print('-------------------------------------------------------')
  98. for row in genres_means:
  99. print('{: <9} | {: >7.2f} | {: >5.2f} | {: >5.2f} | {: >16.2f}'.format(
  100. row[0], row[1], row[2], row[3], row[4]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement