Your job is to write a program that accepts a research area (managed by an organ

WRITE MY ESSAY

Your job is to write a program that accepts a research area (managed by an organ

Your job is to write a program that accepts a research area (managed by an organization called a “Directorate” inside NSF), such as ‘BIO’ or ‘ENG’, and then computes the total grants per year since 1990 in that area. As you’ll discover below, the Python Standard Library provides several functions that will greatly ease your assignment. This assignment will test your ability to do computation (CLO1), read files (CLO2), use lists (CLO4), and use dictionaries (CLO5). It’ll also give an indication of whether you’re ready to learn about using 3rd-party libraries (CLO6).
Download a copy of Awards.csv and put it in the same folder where you’ll put your program. It will be handy for you to test your code. But keep in mind that the auto-grader will actually give a different file when testing and grading your code.
Use your text editor to create a .py file containing a Python program that contains a single function called totals_by_year(directorate) that accepts one parameter named directorate that will specify a research area such as ‘ENG’ (Engineering), ‘BIO’ (Biological Sciences) or ‘GEO’ (Geosciences).
Inside your function, do the following:
Open up the Awards.CSV file
Use the CSV file’s header row to determine the position of three columns: StartDate, AwardedAmountToDate, and NSFDirectorate
For each row,Read the StartDate, AwardedAmountToDate, and NSFDirectorate columns
Compute the year of the StartDate
If the year is earlier than 1990, then ignore the row and move on to the next. (Include 1990 and later. Exclude 1989 and earlier.)
If the NSFDirectorate is not directorate, then ignore the row and move on to the next
Keep a running total, by year, of all the grants’ AwardedAmountToDate given during that year for this directorate
Return a dictionary whose keys are the years and whose entries are the total grants for each year for this directorate
Simplified ExampleTo take a simplified example, suppose that the Awards.csv file only contained the following columns and rows. (The real CSV may have thousands of rows and very many columns, but this simple example will help to illustrate what your function totals_by_year() is supposed to compute.)
StartDateAwardedAmountToDateNSFDirectorate
2/2/2019$295,848.00ENG
4/5/2018$133,638.00BIO
2/17/2017$499,791.00ENG
3/4/2018$48,586.00BIO
1/19/2017$179,963.00BIO
8/8/1987$209,997.00ENG
Calling totals_by_year(‘BIO’) with the CSV above would match 3 rows. The total for 2018 would be $133,638.00+$48,586.00=182224. The total for 2017 would be just $179,963.00. So calling totals_by_year(‘BIO’) with the CSV above would return {2017:179963, 2018:182224}.
Calling totals_by_year(‘ENG’) with the CSV above would match 2 rows. Notice that the last row is before 1990 and would be ignored. The function would return {2017:499791, 2019:295848}.
(In practice, some rows might contain “O/D” which is a special meta-directorate, called the Office of the Directorate. You can treat it like any other directorate. It’s not special from the standpoint of the current assignment.)
Final Hints
The following additional guidance should ease your assignment…
The start date of each grant is stored in the CSV as a string in the format m/d/Y, where m is the month, d is the day, and Y is the year. The datetime module of the Python Standard Library has a function that you can use to convert each string into a datetime. Then, you can obtain the year of the datetime for use in your calculations.. You should have gotten some practice with this module (though not the specific function that you need) during a previous Exploration. You also can read about this function in Chapter 15 of your textbook.
The amount of each grant is stored in the CSV as a string that has a leading dollar sign, one or more comma, and trailing whitespace. You’ll need to remove these undesirable characters before you can call float() to convert the value into a floating-point number. A previous Exploration already discussed how to strip whitespace and remove undesired characters (by replacing them with an empty string) using string-manipulation functions provided by the Python Standard Library.
Do not assume that the StartDate, AwardedAmountToDate, or NSFDirectorate columns will be the only columns. The real CSV passed to your program may actually be much larger than the simplified example above. You cannot assume that the StartDate will be in the first column or in any specific column position, for example. Nor AwardedAmountToDate. Nor NSFDirectorate. You must use the header row of the CSV to determine the right column position. A previous Exploration demonstrated how using certain functionality of the csv module in the Python Standard Library enables you to look up the position of a desired column.

WRITE MY ESSAY

admin Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *