Answer:
Here is the function:
def NumberOfSongs(word): # function definition
count=0 #count the occurrence of word in song
for song in lyrics['Lyrics']: #iterates through song lyrics
if word in str(song): #if word is in the song
count=count+1 #adds 1 to the count
if count!=0: #if word occurs in the songs
return f'{str(count)} songs were found to contain {word} in this dataset' #display the count of the word in the song
else: #if word does not appear in any song
return f'No songs were found to contain the words:{word}' #returns this message if no songs were found with given word
print(NumberOfSongs('like')) #calls method with the word like given as parameter to it
Step-by-step explanation:
You can add the csv file this way:
import pandas as pd
lyrics = pd.read_csv("lyrics.csv", encoding="cp1252")
Now you can use the NumberOfSongs method which iterates through the Lyrics of lyrics.csv and find if any of the songs in the file contains the specified word.
The screenshot of program along with its output is attached. Since the file was not provided i have created a csv file. You can add your own file instead of lyrics.csv