Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help with this question along with the output In this assignment you are to write a Python program to read a CSV file consisting
Need help with this question along with the output
In this assignment you are to write a Python program to read a CSV file consisting of U.S. state information, then create and process the data in JSON format. Specific steps: 1. Read a CSV file of US state information, then create a dictionary with state abbreviation as key and the associated value as a list: {abbrev. [state name, capital, population]). For example, the entry in the dictionary for Virginia would be : {'VA': ['Virginia', 'Richmond', '7078515']}. 2. Create a JSON formatted file using that dictionary. Name the file 'state_json.json'. 3. Visually inspect the file to ensure it's in JSON format. 4. Read the JSON file into your program and create a dictionary. 5. Search the dictionary to display the list of all state names whose population is greater than 5,000,000. Notes: The input file of U.S. state information will be provided with the assignment In processing that data you'll need to read each line using READLINE, or all into one list with READLINES Since the data is comma-separated you'll have to use the string 'split' method to separate the attributes (or fields) from each line and store each in a list. Remember that all the input data will arrive in your program as a character string. To process the population data you'll have to convert it to integer format. The input fields have some extraneous spaces that will have to be removed using the string 'strip' method. As each line is read and split, add an entry for it to the dictionary as described above. . Be sure to import 'json' and use the 'dumps' method to create the output string for writing to the file. The visual inspection is for your benefit and won't be reviewed or graded. . Use the 'loads' method to process the read json file data into a Python data structure. Iterate through the dictionary and compare each state's population to determine which to display. Be sure you've stored the population in the dictionary as an integer so you can do the comparison with 5,000,000Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started