Dr. Granger is interested in studying the factors controlling the size and carbon storage of shrubs. This research is part of a larger area of research trying to understand carbon storage by plants. She has conducted a small preliminary experiment looking at the effect of three different treatments on shrub volume at four different locations. She wants to conduct a preliminary analysis of these data to include in a grant proposal and she would like you to conduct the analysis for her (she might be a world renowned expert in carbon storage in plants, but she sure doesn’t know much about computers). She has placed a data file on the web for you to download.
You might be able to do this analysis by hand in Excel, but Dr. Granger seems to always get funded meaning that you’ll be doing this again soon with a much larger dataset. So, you decide to write a script so that it will be easy to do the analysis again.
Write a Python script that:
numpy
. It has a header row so you’ll need to tell
numpy.loadtxt()
to ignore it by providing the optional argument
skiprows=1
.1.8 +
2 * log(volume)
where volume
is the volume of the shrub (i.e., its length
times its width times its height).shrubs_experiment_results.csv
.This code should use functions to break the code up into manageable pieces. To
help you get started here is a function for exporting the results to a csv
file. To use it you’ll need to copy and paste it into your code. It uses the
csv
module so you’ll need to remember to import it.
def export_to_csv(data, filename):
"""Export list of lists to comma delimited text file"""
outputfile = open(filename, 'wb')
datawriter = csv.writer(outputfile)
datawriter.writerows(data)
outputfile.close()
Optional: If you’d like to test your skills a little more, try: 1. Adding a header row to you output file; and 2. Determining the average carbon in a shrub for each of the different experiments and printing those values to the screen.