Pandas: Get the details of the columns title and genres of the DataFrame
Write a Pandas program to get the details of the columns title and genres of the DataFrame.
Sample Solution:
Python Code :
import pandas as pd
df = pd.read_csv('movies_metadata.csv')
result = df[['title', 'genres']]
print("Details of title and genres:")
print(result)
Sample Output:
Details of title and genres: title \ 0 Toy Story 1 Jumanji 2 Grumpier Old Men 3 Waiting to Exhale 4 Father of the Bride Part II 5 Heat 6 Sabrina 7 Tom and Huck 8 Sudden Death 9 GoldenEye 10 The American President 11 Dracula: Dead and Loving It 12 Balto 13 Nixon 14 Cutthroat Island 15 Casino 16 Sense and Sensibility 17 Four Rooms 18 Ace Ventura: When Nature Calls 19 Money Train 20 Get Shorty 21 Copycat 22 Assassins 23 Powder 24 Leaving Las Vegas 25 Othello 26 Now and Then 27 Persuasion 28 The City of Lost Children 29 Shanghai Triad 30 Dangerous Minds 31 Twelve Monkeys 32 Wings of Courage 33 Babe 34 Carrington 35 Dead Man Walking 36 Across the Sea of Time 37 It Takes Two 38 Clueless 39 Cry, the Beloved Country 40 Richard III 41 Dead Presidents 42 Restoration 43 Mortal Kombat 44 To Die For 45 How To Make An American Quilt 46 Se7en 47 Pocahontas 48 When Night Is Falling 49 The Usual Suspects genres 0 [{'id': 16, 'name': 'Animation'}, {'id': 35, '... 1 [{'id': 12, 'name': 'Adventure'}, {'id': 14, '... 2 [{'id': 10749, 'name': 'Romance'}, {'id': 35, ... 3 [{'id': 35, 'name': 'Comedy'}, {'id': 18, 'nam... 4 [{'id': 35, 'name': 'Comedy'}] 5 [{'id': 28, 'name': 'Action'}, {'id': 80, 'nam... 6 [{'id': 35, 'name': 'Comedy'}, {'id': 10749, '... 7 [{'id': 28, 'name': 'Action'}, {'id': 12, 'nam... 8 [{'id': 28, 'name': 'Action'}, {'id': 12, 'nam... 9 [{'id': 12, 'name': 'Adventure'}, {'id': 28, '... 10 [{'id': 35, 'name': 'Comedy'}, {'id': 18, 'nam... 11 [{'id': 35, 'name': 'Comedy'}, {'id': 27, 'nam... 12 [{'id': 10751, 'name': 'Family'}, {'id': 16, '... 13 [{'id': 36, 'name': 'History'}, {'id': 18, 'na... 14 [{'id': 28, 'name': 'Action'}, {'id': 12, 'nam... 15 [{'id': 18, 'name': 'Drama'}, {'id': 80, 'name... 16 [{'id': 18, 'name': 'Drama'}, {'id': 10749, 'n... 17 [{'id': 80, 'name': 'Crime'}, {'id': 35, 'name... 18 [{'id': 80, 'name': 'Crime'}, {'id': 35, 'name... 19 [{'id': 28, 'name': 'Action'}, {'id': 35, 'nam... 20 [{'id': 35, 'name': 'Comedy'}, {'id': 53, 'nam... 21 [{'id': 18, 'name': 'Drama'}, {'id': 53, 'name... 22 [{'id': 28, 'name': 'Action'}, {'id': 12, 'nam... 23 [{'id': 18, 'name': 'Drama'}, {'id': 14, 'name... 24 [{'id': 18, 'name': 'Drama'}, {'id': 10749, 'n... 25 [{'id': 18, 'name': 'Drama'}] 26 [{'id': 35, 'name': 'Comedy'}, {'id': 18, 'nam... 27 [{'id': 18, 'name': 'Drama'}, {'id': 10749, 'n... 28 [{'id': 14, 'name': 'Fantasy'}, {'id': 878, 'n... 29 [{'id': 18, 'name': 'Drama'}, {'id': 80, 'name... 30 [{'id': 18, 'name': 'Drama'}, {'id': 80, 'name... 31 [{'id': 878, 'name': 'Science Fiction'}, {'id'... 32 [{'id': 10749, 'name': 'Romance'}, {'id': 12, ... 33 [{'id': 14, 'name': 'Fantasy'}, {'id': 18, 'na... 34 [{'id': 36, 'name': 'History'}, {'id': 18, 'na... 35 [{'id': 18, 'name': 'Drama'}] 36 [{'id': 12, 'name': 'Adventure'}, {'id': 36, '... 37 [{'id': 35, 'name': 'Comedy'}, {'id': 10751, '... 38 [{'id': 35, 'name': 'Comedy'}, {'id': 18, 'nam... 39 [{'id': 18, 'name': 'Drama'}] 40 [{'id': 18, 'name': 'Drama'}, {'id': 10752, 'n... 41 [{'id': 28, 'name': 'Action'}, {'id': 80, 'nam... 42 [{'id': 18, 'name': 'Drama'}, {'id': 10749, 'n... 43 [{'id': 28, 'name': 'Action'}, {'id': 14, 'nam... 44 [{'id': 14, 'name': 'Fantasy'}, {'id': 18, 'na... 45 [{'id': 18, 'name': 'Drama'}, {'id': 10749, 'n... 46 [{'id': 80, 'name': 'Crime'}, {'id': 9648, 'na... 47 [{'id': 12, 'name': 'Adventure'}, {'id': 16, '... 48 [{'id': 18, 'name': 'Drama'}, {'id': 10749, 'n... 49 [{'id': 18, 'name': 'Drama'}, {'id': 80, 'name...
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 count the number of rows and columns of the DataFrame (movies_metadata.csv file).
Next: Write a Pandas program to get the details of the movie with title 'Grumpier Old Men'.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics