import pandas import csv #Reading the csv file and creating a dataframe songs=pandas.read_csv("C:\\Users\\Jen\\Desktop\\Rutgers\\Python Meth - Spring 2018\\music.csv") songscaps=songs.apply(lambda x: x.astype(str).str.upper()) SongTitles=songs['title'].tolist() #Creating a blank list to use in the function below results=[] #Inquiries to the user Inquiry2=input("What do you want to search on? \nPlease select the number of your option. \nSelect the number and '?' (eg: 1?) for more info. \n 1. Artist Name \n 2. Year \n 3. Familiarity \n 4. Loudness \n 5. Song Hotness \n 6. Artist Hotness \n 7. Tempo \n 8. Genre \n") Inquiry1=str.upper(input("Artist name? \n")) Inquiry3=str.upper(input("Song name? \n")) if Inquiry3=="": pass else: if Inquiry3 not in SongTitles: print ("Your song is not in the database. Please select another.") Inquiry3=str.upper(input()) else: pass #Artist if Inquiry2=="1": results=songscaps[songscaps['artist_name']==Inquiry1]['title'] #Year elif Inquiry2=="2": interim=songscaps.loc[songscaps['title']==Inquiry3].year.item() interim2=songscaps.loc[songscaps['title']==Inquiry3].artist_name.item() results=songscaps[songscaps['year']==interim] Titles=results['title'].tolist() Artists=results['artist_name'].tolist() A1=[x+" by "+y for x,y in zip(Titles,Artists)] A2=(Inquiry3+" by "+interim2) A1.remove(A2) else: print ('Hi') #Printing out the results based off of user input print ("There are ", len(A1), " results.") numberofresults=input("Press 'A' if you'd like all results, or input the number of results you'd like to see.") if str.upper(numberofresults)=="A" or str.upper(numberofresults)=="ALL": print ('\n'.join(A1)) else: print ('\n'.join(A1[:int(numberofresults)])) #Saving the results into a write out file Inquiry3=input("Would you like to save your results? All results will be saved. Y or N? ") #if str.upper(Inquiry3)=="YES" or str.upper(Inquiry3)=="Y": # WRITE TO FILE #else: # pass
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question