Question
Task: For both genres, calculate the percentages of tracks that users skipped straight away. Divide the number of tracks that the users skipped, rock_haters and
Task: For both genres, calculate the percentages of tracks that users skipped straight away. Divide the number of tracks that the users skipped, rock_haters and pop_haters, respectively, by the total number of rock and pop tracks. The total number of tracks in a genre is equal to the number of instances in the rock and pop tables, or the value of the shape[0] attribute of these tables. Save the results to the variables rock_skip and pop_skip. Print the values of these new variables as percentages, precise to one decimal place, like below:
Percentage of rock tracks skipped: ... Percentage of pop tracks skipped: ...
Hint: When printing, pass each variable as an argument of the format() function with the template {:.1%}. Don't forget to comment out the line with print() from the previous task.
code: import pandas as pd
df = pd.read_csv('music_log.csv')
rock = df[(df.genre == 'rock')]
rock_time=rock['total play']
rock_haters=rock_time[rock_time<=5].count()
pop = df[(df.genre == 'pop')]
pop_time=pop['total play']
pop_haters=pop_time[pop_time<=5].count() here is column names of the dataset Index([' user_id', 'total play', 'Artist', 'genre', 'track'], dtype='object')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started