Question: IN PYTHON! I am having troubles writing the data_cleaning function For part 1 we're simply going to open the files and read them to parse

IN PYTHON! I am having troubles writing the data_cleaning function

For part 1 we're simply going to open the files and read them to parse the data. The calculations and heat map will happen in the subsequent weeks.

You will need to write 2 functions: open_file() and data_cleaning()

The program skeleton will look something like this:

def openFiles(filename): pass #your code here def dataCleaning(**kwargs): pass #your code here if '__name__' == '__main__': stateDic = loadStateDic("statecode.csv') # utility function to create a 'statecode : state full name' dictionary #open data files smoking_data = openFiles("cigarette.csv") smoking_data_clean = dataCleaning(data=smoking_data , state_dict=stateDic, state_col=0, rate_col=1) # rest of your code here 

The openFiles function will take a name of a file, attempt to open it, and either return the file as a list of strings (except the title row) or return an empty list

Ex:

 smoking_data = open_file("cigarette.csv") 

The dataCleaning function will take the data and convert each row to a list. This may include stripping extraneous whitespace and quotes. It will return a dictionary with state names and data values.

Ex:

smoking_list = openFiles('cigarette.csv') smoking_data = dataCleaning(data=smoking_list, state_dict=stateDic, state_col=1, rate_col=7) 

Given

["2016","Alabama","BRFSS","Cigarette Use (Adults)","Current Smoking","","Percentage","21.5","20.1","22.9","6764","Overall","All Ages","All Races","All Grades"] ["2016","Alaska","BRFSS","Cigarette Use (Adults)","Current Smoking","","Percentage","19.0","16.7","21.3","2811","Overall","All Ages","All Races","All Grades"] 

Your function should return a dictionary

{ 'Alabama':21.5, 'Alaska': 19.0, ... } 

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 Databases Questions!