USING PYTHON 1. What is the most popular boy name in 2010? This function should
ID: 3753264 • Letter: U
Question
USING PYTHON
1. What is the most popular boy name in 2010? This function should return a tuple of type string and integer.
2. List all the girl names which number is greater than 10000? This function should return a list of string.
3. Count the occurances of all the boy's names whose number is greater than 8000? This function should return an integer.
4. Given a name and gender, what is the number of it? This function should return an integer.
# Data: National Data on the relative frequency of given names in the population of U.S. births where the individual has a Social Security Number. # yob2010.csv is the record of 2010. It has the format "Name, Gender, Number", where name is 2 to 15 characters, gender is M (male) or F (female), and "Number" is the number of occurences of the name # Run this cell to create a list of tuples called baby-list. # The three elements of each tuple is in the format of (name, gender, number) # Both name and gender are of type string and number is of type integer # ! ! ! Don't modify this cell !! ! import pandas as pd df pd.read_csv ('yob2010.csv', header-e) name_list -list(df.Name) gender list - list(df.Gender) list(df.Number) number_list - list (map (int,list (df.Number))) baby_list - list(zip(name_list, gender_list, number_list )) baby_list Out [131]'Aaban', M, 9), 'Aadam, 'M, 7), Aadan, 'M', 11), 'Aaden, 'M, 448), Aadhav', M, 13), 'Aadhavan' 'M', 5), 'Aadhya, F, 19), ('Aadi 'M', 54), ('Aadil', '' 11),Explanation / Answer
#1 def popular_boy_name(): num=0 name=baby_list[0][0] for i in baby_list: if i[2]>num and i[1]=='M': num=i[2] name=i[0] return name,num #2 def girl10000(): girls=[] for i in baby_list: if i[2]>10000 and i[1]=='F': girls.append(i[0]) return girls #3 def boys8000(): occur=0 for i in baby_list: if i[2]>8000 and i[1]=='M': occur+=1 return occur #4 def name_search(name,gender): for i in baby_list: if i[0]==name and i[1]==gender: return i[2] return None
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.