Pandas: Get the longest runtime and shortest runtime
Pandas: IMDb Movies Exercise-14 with Solution
Write a Pandas program to get the longest runtime and shortest runtime.
Sample Solution:
Python Code :
import pandas as pd
df = pd.read_csv('movies_metadata.csv')
small_df = df[['title', 'runtime']]
run_time = small_df['runtime']
print(small_df)
print("===============================================")
print("Longest runtime")
print(run_time.max())
print("Shortest runtime")
print(run_time.min())
Sample Output:
title runtime 0 Toy Story 81.0 1 Jumanji 104.0 2 Grumpier Old Men 101.0 3 Waiting to Exhale 127.0 4 Father of the Bride Part II 106.0 5 Heat 170.0 6 Sabrina 127.0 7 Tom and Huck 97.0 8 Sudden Death 106.0 9 GoldenEye 130.0 10 The American President 106.0 11 Dracula: Dead and Loving It 88.0 12 Balto 78.0 13 Nixon 192.0 14 Cutthroat Island 119.0 15 Casino 178.0 16 Sense and Sensibility 136.0 17 Four Rooms 98.0 18 Ace Ventura: When Nature Calls 90.0 19 Money Train 103.0 20 Get Shorty 105.0 21 Copycat 124.0 22 Assassins 132.0 23 Powder 111.0 24 Leaving Las Vegas 112.0 25 Othello 123.0 26 Now and Then 100.0 27 Persuasion 104.0 28 The City of Lost Children 108.0 29 Shanghai Triad 108.0 30 Dangerous Minds 99.0 31 Twelve Monkeys 129.0 32 Wings of Courage 50.0 33 Babe 89.0 34 Carrington 121.0 35 Dead Man Walking 122.0 36 Across the Sea of Time 51.0 37 It Takes Two 101.0 38 Clueless 97.0 39 Cry, the Beloved Country 106.0 40 Richard III 104.0 41 Dead Presidents 119.0 42 Restoration 117.0 43 Mortal Kombat 101.0 44 To Die For 106.0 45 How To Make An American Quilt 116.0 46 Se7en 127.0 47 Pocahontas 81.0 48 When Night Is Falling 96.0 49 The Usual Suspects 106.0 =============================================== Longest runtime 192.0 Shortest runtime 50.0
Python-Pandas Code Editor:
Sample Table:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program to get those movies whose revenue more than 2 million and spent less than 1 million.
Next: Write a Pandas program to calculate the number of votes garnered by the 70% movie.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/python-exercises/pandas/movies/python-pandas-movies-exercise-14.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics