Write a Python (console) program which: Accepts the URL of the CDC data set, your MongoDB login and your MongoDB password as command-line pararameters.

BA371 Assignment 3: Python/MongoDB — store and retrieve CDC data
This assignment assumes that you are familiar with the various topics demonstrated and practiced in the following labs:
Python — Refresher
Python — Database Communications (Part 2)
Python — XML/JSON
The CDC (Centers for Disease Control) makes available lots of data; much of it in JSON or XML form.
The CDC dataset linked here covers 1071 data records on life expectancy (at birth) for black, white and ‘all races’ males, females and ‘all genders’ for the period 1900-2018. (note: the data do not contain any information for other races/ethnicities and other gender types).
In addition to these demographic data, a lot of metadata (data describing the data) are provided.
Take a look at the data to develop a feeling for how the data are structured.
Note how the dataset contains a single JSON structure ({}), which itself contains two (2) structures, one called meta and one called data ({meta: {}, data {}}). Our data resides in the data structure.
Notice how the data structure itself is a list of lists ([ […], […], …, […] ]) with each of the inner lists representing a single row of data. Here is the first row of data:
[ “row-rhmg~ppfg~kih8”, “00000000-0000-0000-20F5-93F72E08E03C”, 0, 1599577329, null, 1599577329, null, “{ }”, “1900”, “All Races”, “Both Sexes”, “47.3”, “2518.0” ]
We are interested in storing only the following variables in MongoDB: year, race, gender, and life expectancy.
year: field 8
race: field 9
gender: field 10
life expectancy: field 11
Your assignment
Write a Python (console) program which:
Accepts the URL of the CDC data set, your MongoDB login and your MongoDB password as command-line pararameters. For instance, if your program is stored in the file foo.py, you should be able to run your program on the command-line as follows:
python foo.py https://data.cdc.gov/api/views/w9j2-ggv5/rows.json Your_MongoDB_Login Your_MongoDB_Password
Explanation: since we do not want to hardcode our MongoDB login and password in the code, we need another way to let the code ‘know’ these two items of information. We have several options to do this:
One way would be to let the code prompt the user for this information. However, doing it that way would imply that the user must be present at the keyboard every time the program runs. This is not feasible for programs which must run automatically, e.g. on a schedule.
A second way to do this would be to store the items in a file and let the program read the file.
A third way —the way we will use here— is to pass the items on the command-line when the program is called to run as shown above.
Downloads the CDC data from the web.
Extracts year, race, gender, and life expectancy from the 1071 records and stores them as 1071 documents (records) in an empty(!!) MongoDB collection named cdcCollection.
After storing the data in cdcCollection, runs the following two (2) MongoDB queries and report their results:
Life expectancy of women (All Races) in 1956 (result: 72.9)
Count of all cases with life expectancy > 75 (result: 217)
Helpful hints
See the XML/JSON lab for how to download a JSON dataset from the web.
Since the data must be stored in an empty(!!) collection with the name cdcCollection, try deleting all records from that collection before storing any in it:
If we have the whole dataset in a variable json_data, we can get the data list out like this:
our_data = json_data[“data”]
And since our_data will be a list, we can loop through it to get each of the rows out:
for row in our_data:
year = int(row[8])
When you read JSON field values from a JSON structure or dict, they are read as strings. If you want to treat them as numbers, cast them accordingly.
There may be a few cases in which the life expectancy data is missing and converting to a number will fail. In those cases, simply store the life expectancy as “null”.
Once we have the data extracted from the row, we can make a dict out of it that we can then send to Mongo for storage:
entry = {“year” : year, “race” : race, “gender” : gender, “expect” : expect}
Then insert it into our Mongo collection (see Python — Database Communications (Part 2) lab for how to do that.
Once all the data are in Mongo, we can query them (see the Python — Database Communications (Part 2) lab for how to do that.
Review criteria

Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.


Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.


Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.


Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.


Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.