Question: USING PYTHON: Notes at the end Two large files are needed to answer these questions, however they are too large and cannot be uploaded, if

USING PYTHON: Notes at the end

Find Texas population. Hint: total population of Texas in 2010 census was

Two large files are needed to answer these questions, however they are too large and cannot be uploaded, if possible, please help understand code by answering to the best of your ability. 

 

Find Texas population. Hint: total population of Texas in 2010 census was 25.1 Million. In [5]: from census 2010 import allData import pandas as pd In [44]: pops pops = = pd. '?' (allData['TX']) # convert it to a data frame In [47]: TXPopulation TXPopulation TXPopulation = pops.'?1'('?2) [0] # 21: function that adds up :-) ?2: the addition function works # recall that the addition function works column wise Out [47]: 25145561 Question 1.b (15 points): US population Find total population of US. Hint: total population of Texas in 2010 census was 308.7 Million. In [15]: total_pop = 0 In [ ]: total pop Out [15]: 308745538 for var in allData.'?'(): # allData is a dictionary. We Loop through its keys. pops = pd. '?' (allData["?"]) # convert it to a data frame # the sum works row wise. total pop pops.sum("?")[0] Question 1.c (10 points): The most populated TX county Find the most populated county in Texas In [48]: TXCountMaxPop TXCountMaxPop = pops."?1"("?2") [0] # ?1: function to find the largest value #22: function 21 works row wise TXCountMaxPop Out [48]: 4092459 In [] In [51]: county = "?" # create an empty list for var in list (pops): if pops.loc ['pop',"?"] == TXCountMaxPop: county. '?'(var) # add var to the list county print(county) ['Harris'] Question 1.d (15 points): the most populated county in each state Find the most populated county in each state. HighpopCounty = '?' # create an empty dictionary for state in allData."?"(): # we what to Loop through keys of the dictionary pops = pd. '?1' (allData['?2']) # ?1: convert to data frame, ?2: this value comes from the for Loc CountMaxPop pops.max (axis=1)[0] = for county in list(pops): if pops.loc ['pop', '?'] == CountMaxPop: #?: this value comes from the for Loop :-) HighpopCounty[state] = {} HighpopCounty[state] [county] = CountMaxPop HighpopCounty Question 2 (20 points): import alic.txt and cound the number of words and characters in it. Count the number of words in the txt file and find the most repeated one. In your program, first convert all words to lower case and then convert the first character to the upper case. Then do the analysis. We are not interested in the following words: The, A, And, To, It Banwords=['The', 'A', 'And', 'To', 'It'] |filename = 'alice.txt' text = '?' (filename) #open the file print('Please Wait, Counting the number of words..') counts = ?' # create an empty dictionary the file for line? text: # keyword in the for Loop line line.'?'() #convert to Lower Lettres. line = line. '?'() #convert the first letter to capital lettre. words = line.'?'() #spereate the words in the Line based on whitespace for word in words: word = word.rstrip(''').,'s,'5,)",)")`"''') word = word. 1strip('''(,", (","(''') if word "?" in Banwords: # the missing keyword Let the Loop continue if the word is not in if word in counts: counts [word] = counts [word]+1 counts [word] = 1 MaxRep = 0 Maxword = 4 else: for k,v in counts. '?'(): # we need both keys and values of the dictionary in the Loop :-) if v > MaxRep: MaxRep = v Maxword = k print (Maxword, is the most repeted word with ',MaxRep, 'times')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!