<jupyter_start><jupyter_text>To extract the most popular names in any given year1. Sorting a dataframe  by a column2. Dropping columns from a Dataframe3. Joining frames based on index4. Counting values in a Series<jupyter_code>#Select all data for a year using a loc selection object

allyears_indexed.loc['M',:,2008].head()
#Next sort this selection with larger numbers on top

allyears_indexed.loc['M',:,2008].sort_values('number',ascending = False).head()<jupyter_output><empty_output><jupyter_text>The most popular boy name in 2008 was Jacob<jupyter_code>#Assign this to a table by feeding this code to pop2008
 
pop2008 = allyears_indexed.loc['M',:,2008].sort_values('number',ascending = False).head()


#Reset the index and drop columns that are not required

pop2008.reset_index().drop(['sex','year','number'],axis=1).head()
#Encapsulate these manipulations into a function so that we can copy
#the top ten for any year.

def topten(sex,year):
    simple = allyears_indexed.loc[sex,:,year].sort_values('number',ascending=False).reset_index()
    simple = simple.drop(['sex','year','number'],axis=1).head(10)
    
    simple.columns = [year]  #change name of one column to year
    simple.index = simple.index+1
    
    return simple
topten('M',2009)
#To compare several years this way compute another function that takes
#a range of years and compute top tens for each year and then will use
#pandas function join to put them in a single dataframe.

def toptens(sex,year0,year1):
    years = [topten(sex,year) for year in range(year0,year1+1)]
    
    return years[0].join(years[1:])


toptens('M',2000,2010)
toptens('F',1985,1995)
#Take the six most popular names in this decade and plot 
#a popularity across all years.

#To see the rise and fall and eventual defeat we turn this dataframe 
#into a series by stacking it

toptens('F',1985,1995).stack().head()
#to compute counts of all the values 

toptens('F',1985,1995).stack().value_counts()
#Plot the first six, need to grab the values from the index of this series

popular = toptens('F',1985,1995).stack().value_counts().index[:6]
pp.figure(figsize=(12,2.5))

for name in popular:
    plotname('F',name)
    
pp.legend(popular)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11555755395683454, 'fraction_numerical': 0.041816546762589925, 'mean_word_length': 5.23249299719888, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '298222', 'license': 'MIT', 'n_tokens_mistral': 775, 'n_tokens_neox': 701, 'n_words': 238, 'path': 'Pandas - Baby name Popularity Project/03 top ten.ipynb', 'repo_name': 'AryaDevops/Python-for-DataScience', 'size': '2224'}