Lab 03

CSCI 1913 – Introduction to Algorithms, Data Structures, and Program Development

Introduction

In this lab you will be manipulating data that is coming from csv (comma separated values) files

  • You do not have to write code to read files for this lab (that part of the code is provided to you)
  • You do have to understand what the code provided is doing
  • You will manipulate a list of dictionaries

Understanding load(filename)

The docstring for load(filename) says:

“““load the CSV file by name, return list of dictionaries, each dictionary describes one row of the file”“”

You have a few calls to load(filename) in weather_tester.py:

test_file_list = load("test_file.csv")
  • What does test_file_list[0] return?
  • What does test_file_list[0]["Max_Temperature"] return?

Understanding load(filename)

test_file_list = load("test_file.csv")
  • What does test_file_list[0] return? The following dictionary:
{ "Max_Temperature" : 6.0,
  "Min_Temperature" : -9.0, 
  "Precipitation"   : "T",
  "Snow"            : "T",
  "Snow_Depth"      : 9.0 }
  • What does test_file_list[0]["Max_Temperature"] return? 6.0

Retrieving values

What does the following code print?

messy_file_list = load("messy_file.csv")
print(messy_file[0]["Date"])

What does the following code print?

messy_file_list = load("messy_file.csv")
print(messy_file[0]["Date"][0])

Retrieving values

What does the following code print?

messy_file_list = load("messy_file.csv")
print(messy_file[0]["Date"])
"2010-01-01"

What does the following code print?

messy_file_list = load("messy_file.csv")
print(messy_file[0]["Date"][0])
"2"

Documentation

Remember to document your code!

Add at the top of python file your name, and the name of any lab partnersyou worked with, as well as docstrings for each function.

  • Use good variable names - python prefers snake_case naming
  • in-line comments #
  • Docstrings - strings included as first lines of programs and functions (careful with indentation)