Question

In: Computer Science

# columns are [0]title [1]year [2]rating [3]length(min) [4]genre [5]budget($mil) [6]box_office_gross($mil) oscar_data = [ ["The Shape of...

# columns are [0]title [1]year [2]rating [3]length(min) [4]genre [5]budget($mil) [6]box_office_gross($mil)
oscar_data = [
["The Shape of Water", 2017, 6.914, 123, ['sci-fi', 'drama'], 19.4, 195.243464],
["Moonlight", 2016, 6.151, 110, ['drama'], 1.5, 65.046687],
["Spotlight", 2015, 7.489, 129, ['drama', 'crime', 'history'], 20.0, 88.346473],
["Birdman", 2014, 7.604, 119, ['drama', 'comedy'], 18.0, 103.215094],
["12 Years a Slave", 2013, 7.71, 133, ['drama', 'biography', 'history'], 20.0, 178.371993],
["Argo", 2012, 7.517, 120, ['thriller', 'drama', 'biography'], 44.5, 232.324128],
["The Artist", 2011, 7.942, 96, ['drama', 'melodrama', 'comedy'], 15.0, 133.432856],
["The King\'s Speech", 2010, 7.977, 118, ['drama', 'biography', 'history'], 15.0, 414.211549],
["The Hurt Locker", 2008, 7.298, 126, ['thriller', 'drama', 'war', 'history'], 15.0, 49.230772],
["Slumdog Millionaire", 2008, 7.724, 120, ['drama', 'melodrama'], 15.0, 377.910544],
["No Country for Old Men", 2007, 7.726, 122, ['thriller', 'drama', 'crime'], 25.0, 171.627166],
["The Departed", 2006, 8.456, 151, ['thriller', 'drama', 'crime'], 90.0, 289.847354],
["Crash", 2004, 7.896, 108, ['thriller', 'drama', 'crime'], 6.5, 98.410061],
["Million Dollar Baby", 2004, 8.075, 132, ['drama', 'sport'], 30.0, 216.763646],
["The Lord of the Rings: Return of the King", 2003, 8.617, 201, ['fantasy', 'drama', 'adventure'], 94.0, 1119.110941],
["Chicago", 2002, 7.669, 113, ['musical', 'comedy', 'crime'], 45.0, 306.776732],
['A Beautiful Mind', 2001, 8.557, 135, ['drama', 'biography', 'melodrama'], 58.0, 313.542341],
["Gladiator", 2000, 8.585, 155, ['action', 'drama', 'adventure'], 103.0, 457.640427],
["American Beauty", 1999, 7.965, 122, ['drama'], 15.0, 356.296601],
["Shakespeare in Love", 1998, 7.452, 123, ['drama', 'melodrama', 'comedy', 'history'], 25.0, 289.317794],
["Titanic", 1997, 8.369, 194, ['drama', 'melodrama'], 200.0, 2185.372302],
["The English Patient", 1996, 7.849, 155, ['drama', 'melodrama', 'war'], 27.0, 231.976425],
["Braveheart", 1995, 8.283, 178, ['drama', 'war', 'biography', 'history'], 72.0, 210.409945],
["Forrest Gump", 1994, 8.915, 142, ['drama', 'melodrama'], 55.0, 677.386686],
["Schindler\'s List", 1993, 8.819, 195, ['drama', 'biography', 'history'], 22.0, 321.265768],
["Unforgiven", 1992, 7.858, 131, ['drama', 'western'], 14.4, 159.157447],
["Silence of the Lambs", 1990, 8.335, 114, ['thriller', 'crime', 'mystery', 'drama', 'horror'], 19.0, 272.742922],
["Dances with Wolves", 1990, 8.112, 181, ['drama', 'adventure', 'western'], 22.0, 424.208848],
["Driving Miss Daisy", 1989, 7.645, 99, ['drama'], 7.5, 145.793296],
["Rain Man", 1988, 8.25, 133, ['drama'], 25.0, 354.825435],
]


def column_sum(data, column):
result = 0
for row in data:
result += row[column]
return result

def column_mean(data, column):
total = column_sum(oscar_data, 6)
mean = total / len(data)
return mean


# < write code here >
  

mean_score = column_mean(oscar_data, 2)
print('Average rating: {:.2f}'.format(mean_score))

mean_length = column_mean(oscar_data, 3)
print('Average length: {:.2f} min.'.format(mean_length))

mean_budget = column_mean(oscar_data, 5)
print('Average budget: ${:.2f} mil.'.format(mean_budget))

mean_gross = column_mean(oscar_data, 6)
print('Average revenue: ${:.2f} mil.'.format(mean_gross))

Solutions

Expert Solution

ANSWER:

As nothing is described in question about your query, I assume you are worried about your output which is same for every statement i.e. function call.

I have provided the properly commented and indented code so you can easily copy the code as well as check for correct indentation.

I have provided the output image of the code so you can easily cross-check for the correct output of the code.

Have a nice and healthy day!!

CODE

# columns are [0]title [1]year [2]rating [3]length(min) [4]genre [5]budget($mil) [6]box_office_gross($mil)
oscar_data = [
["The Shape of Water", 2017, 6.914, 123, ['sci-fi', 'drama'], 19.4, 195.243464],
["Moonlight", 2016, 6.151, 110, ['drama'], 1.5, 65.046687],
["Spotlight", 2015, 7.489, 129, ['drama', 'crime', 'history'], 20.0, 88.346473],
["Birdman", 2014, 7.604, 119, ['drama', 'comedy'], 18.0, 103.215094],
["12 Years a Slave", 2013, 7.71, 133, ['drama', 'biography', 'history'], 20.0, 178.371993],
["Argo", 2012, 7.517, 120, ['thriller', 'drama', 'biography'], 44.5, 232.324128],
["The Artist", 2011, 7.942, 96, ['drama', 'melodrama', 'comedy'], 15.0, 133.432856],
["The King\'s Speech", 2010, 7.977, 118, ['drama', 'biography', 'history'], 15.0, 414.211549],
["The Hurt Locker", 2008, 7.298, 126, ['thriller', 'drama', 'war', 'history'], 15.0, 49.230772],
["Slumdog Millionaire", 2008, 7.724, 120, ['drama', 'melodrama'], 15.0, 377.910544],
["No Country for Old Men", 2007, 7.726, 122, ['thriller', 'drama', 'crime'], 25.0, 171.627166],
["The Departed", 2006, 8.456, 151, ['thriller', 'drama', 'crime'], 90.0, 289.847354],
["Crash", 2004, 7.896, 108, ['thriller', 'drama', 'crime'], 6.5, 98.410061],
["Million Dollar Baby", 2004, 8.075, 132, ['drama', 'sport'], 30.0, 216.763646],
["The Lord of the Rings: Return of the King", 2003, 8.617, 201, ['fantasy', 'drama', 'adventure'], 94.0, 1119.110941],
["Chicago", 2002, 7.669, 113, ['musical', 'comedy', 'crime'], 45.0, 306.776732],
['A Beautiful Mind', 2001, 8.557, 135, ['drama', 'biography', 'melodrama'], 58.0, 313.542341],
["Gladiator", 2000, 8.585, 155, ['action', 'drama', 'adventure'], 103.0, 457.640427],
["American Beauty", 1999, 7.965, 122, ['drama'], 15.0, 356.296601],
["Shakespeare in Love", 1998, 7.452, 123, ['drama', 'melodrama', 'comedy', 'history'], 25.0, 289.317794],
["Titanic", 1997, 8.369, 194, ['drama', 'melodrama'], 200.0, 2185.372302],
["The English Patient", 1996, 7.849, 155, ['drama', 'melodrama', 'war'], 27.0, 231.976425],
["Braveheart", 1995, 8.283, 178, ['drama', 'war', 'biography', 'history'], 72.0, 210.409945],
["Forrest Gump", 1994, 8.915, 142, ['drama', 'melodrama'], 55.0, 677.386686],
["Schindler\'s List", 1993, 8.819, 195, ['drama', 'biography', 'history'], 22.0, 321.265768],
["Unforgiven", 1992, 7.858, 131, ['drama', 'western'], 14.4, 159.157447],
["Silence of the Lambs", 1990, 8.335, 114, ['thriller', 'crime', 'mystery', 'drama', 'horror'], 19.0, 272.742922],
["Dances with Wolves", 1990, 8.112, 181, ['drama', 'adventure', 'western'], 22.0, 424.208848],
["Driving Miss Daisy", 1989, 7.645, 99, ['drama'], 7.5, 145.793296],
["Rain Man", 1988, 8.25, 133, ['drama'], 25.0, 354.825435],
]

# function to sum column wise in given data
def column_sum(data, column):
    # defining result counter, to add sum of each element of column
    result = 0
    # looping through row
    for row in data:
        # fetching data at column and adding to result
        result += row[column]
    # returning result
    return result

# function column_mean, return mean of data according to column
def column_mean(data, column):
    # calculating sum of specified column using function column_sum
    total = column_sum(data, column)
    # dividing total by total rows
    mean = total / len(data)
    # returning mean
    return mean


# < write code here >
mean_score = column_mean(oscar_data, 2)
print('Average rating: {:.2f}'.format(mean_score))

mean_length = column_mean(oscar_data, 3)
print('Average length: {:.2f} min.'.format(mean_length))

mean_budget = column_mean(oscar_data, 5)
print('Average budget: ${:.2f} mil.'.format(mean_budget))

mean_gross = column_mean(oscar_data, 6)
print('Average revenue: ${:.2f} mil.'.format(mean_gross))

OUTPUT IMAGE


Related Solutions

exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6...
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6 1 5 6 8 2 4 6 7 3 4 5 9 10 5 8 9 4 7 9 6 7 8 6 How can I detect when 'cin' starts reading from a new line. The amount of numbers in each row is unknown. I need them in type 'int' to use the data.
COLLAPSE Overall Rating: 1 2 3 4 5 Your Rating: 1 2 3 4 5 "Sikh...
COLLAPSE Overall Rating: 1 2 3 4 5 Your Rating: 1 2 3 4 5 "Sikh Rituals and Practices"  Please respond to the following in at least 250 words and include any sources you use: What are the key beliefs and practices in Sikhism? From the religions we have studied so far, identify the religion that you believe has the most in common with Sikhism. Explain your choice by discussing at least three comparative aspects of these two religions. Which one...
Title Year Released U.S. Box Office Receipts (Inflation Adjusted Millions $) Rating Genre Budget (Non-Inflation Adjusted...
Title Year Released U.S. Box Office Receipts (Inflation Adjusted Millions $) Rating Genre Budget (Non-Inflation Adjusted Millions $) World Box Office Receipts (Non-Inflation Adjusted Millions $) U.S. Box Office Receipts (Non-Inflation Adjusted Millions $) Gone With the Wind 1939 $1,650 G Drama $3 $391 $199 Star Wars 1977 $1,426 PG SciFi/Fantasy $11 $798 $461 The Sound of Music 1965 $1,145 G Musical -- $163 $163 E.T. 1982 $1,132 PG SciFi/Fantasy -- $757 $435 Titanic 1997 $1,096 PG-13 Drama $200 $2,185...
x (Bins) frequency 0 0 1 0 2 0 3 2 4 5 5 8 6...
x (Bins) frequency 0 0 1 0 2 0 3 2 4 5 5 8 6 13 7 33 8 42 9 66 10 77 11 105 12 103 13 110 14 105 15 84 16 70 17 51 18 40 19 27 20 27 21 15 22 5 23 7 24 2 25 2 26 1 27 0 28 0 29 0 30 0 (7) On the Histogram worksheet, calculate all frequencies of the distribution using the table shown....
Year 0 Year 1 Year 2 Year 3 Year 4 Year 5 Year 6 Year 7...
Year 0 Year 1 Year 2 Year 3 Year 4 Year 5 Year 6 Year 7 MACRS Depreciation Rate ?14.29% ?24.49% ?17.49% ?12.49% ?8.93% ?8.92% ?8.93% ?4.46% Massive? Amusements, an owner of theme? parks, invests $ 60 million to build a roller coaster. This can be depreciated using the MACRS schedule shown above. How much less is the depreciation tax shield for year 4 under MACRS depreciation than under? 7-year, straight-line? depreciation, if the tax rate is 35?%?
COLLAPSE Overall Rating: 1 2 3 4 5 1 2 3 4 5 " Service Positioning...
COLLAPSE Overall Rating: 1 2 3 4 5 1 2 3 4 5 " Service Positioning versus Product Process " Please respond to the following: Examine the roles of Enterprise Resource Planning (ERP) and Customer Relationship Management (CRM) in business. Determine how each system can play a critical role in managing value chains. How does LaRosa’s Pizzeria use this technology in order to improve the supply chain and value chain operations? Determine the ways this technology has helped to deliver...
These are the cash flows. Year 0 1 2 3 4 5 6   Revenue 3.2000 4.0000...
These are the cash flows. Year 0 1 2 3 4 5 6   Revenue 3.2000 4.0000 5.6000 5.6000 4.0000 2.4000   Expenses .7200 .9000 1.2600 1.2600 .9000 .5400   Depreciation .9500 .9500 .9500 .9500 .9500 .9500   Pretax profit 1.5300 2.1500 3.3900 3.3900 2.1500 .9100   Tax .5355 .7525 1.1865 1.1865 .7525 .3185   Net income .9945 1.3975 2.2035 2.2035 1.3975 .5915   OCF 1.9445 2.3475 3.1535 3.1535 2.3475 1.5415      Cash flow investment −5.7000 .4362    Change in NWC −.3200 −.0800 −.1600 0.0000 .1600 .1600 .2400...
(a) Find the exact length of the curve y = 1/6 (x2 + 4)(3/2) , 0...
(a) Find the exact length of the curve y = 1/6 (x2 + 4)(3/2) , 0 ≤ x ≤ 3. (b) Find the exact area of the surface obtained by rotating the curve in part (a) about the y-axis. I got part a I NEED HELP on part b
6 5 4 5 0 0 13 48 6 1 0 7 2 0 1 1...
6 5 4 5 0 0 13 48 6 1 0 7 2 0 1 1 0 2 11 5 11 27 4 0 6 Create Standard Deviation Chart (Normal Distribution Curve)
Year Promisedcash flows Expectedcash flows 1 6 5 2 6 5 3 6 5 4 6...
Year Promisedcash flows Expectedcash flows 1 6 5 2 6 5 3 6 5 4 6 5 5 6 5 6 6 5 7 6 5 8 6 5 9 6 5 10 106 95 What is the present value today of promised cash flows at 6%? If the price of the bond is 80, what is the yield to maturity of the bond using the promised cash flows? What is the present value today of the expected cash flows...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT