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.


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.

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.)
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.



Best Custom Essay Writing Services

Looking for unparalleled custom paper writing services? Our team of experienced professionals at AcademicWritersBay.com is here to provide you with top-notch assistance that caters to your unique needs.

We understand the importance of producing original, high-quality papers that reflect your personal voice and meet the rigorous standards of academia. That’s why we assure you that our work is completely plagiarism-free—we craft bespoke solutions tailored exclusively for you.

Why Choose AcademicWritersBay.com?

  • Our papers are 100% original, custom-written from scratch.
  • We’re here to support you around the clock, any day of the year.
  • You’ll find our prices competitive and reasonable.
  • We handle papers across all subjects, regardless of urgency or difficulty.
  • Need a paper urgently? We can deliver within 6 hours!
  • Relax with our on-time delivery commitment.
  • We offer money-back and privacy guarantees to ensure your satisfaction and confidentiality.
  • Benefit from unlimited amendments upon request to get the paper you envisioned.
  • We pledge our dedication to meeting your expectations and achieving the grade you deserve.

Our Process: Getting started with us is as simple as can be. Here’s how to do it:

  • Click on the “Place Your Order” tab at the top or the “Order Now” button at the bottom. You’ll be directed to our order form.
  • Provide the specifics of your paper in the “PAPER DETAILS” section.
  • Select your academic level, the deadline, and the required number of pages.
  • Click on “CREATE ACCOUNT & SIGN IN” to provide your registration details, then “PROCEED TO CHECKOUT.”
  • Follow the simple payment instructions and soon, our writers will be hard at work on your paper.

AcademicWritersBay.com is dedicated to expediting the writing process without compromising on quality. Our roster of writers boasts individuals with advanced degrees—Masters and PhDs—in a myriad of disciplines, ensuring that no matter the complexity or field of your assignment, we have the expertise to tackle it with finesse. Our quick turnover doesn’t mean rushed work; it means efficiency and priority handling, ensuring your deadlines are met with the excellence your academics demand.

ORDER NOW and experience the difference with AcademicWritersBay.com, where excellence meets timely delivery.