Traversals

A group of problems that help you to practice looping over and making decisions about data. Here you will combine if statements and loops to do traversals over a collection of data.

Intro to Traversing Data

For this task, look over the random.csv data set and use a loop to traverse column 0. As the program traverses the column, output all the values in order, 1 through 30.

Traversing Data in Reverse

For this task, look over the random.csv data set and change the program so it traverses column 0 in reverse order. As the program traverses the column, output all the values in reverse order, 30 through 1.

Traversing Data to Sum

In this new program, use the Dogs.csv data set. Traverse the maximum lifespan column and find the sum of all the values in the column. Then, output the sum in the following format.

The sum of column 5 is 1417

Using Size and Traverals

Now, use the Dogs.csv data set to calculate the mean maximum lifespan of the dog breeds. This program already finds the sum of the column, add the code to calculate the mean, and output the result. The output should have the following format.

The mean lifespan is 13.495238095238095

Searching with Traverals

Continue to use the Dogs.csv data set to search for the largest value in the maximum weight column. This program already loops through the entire column. Add the blocks to search for the greatest value in the column. Then the program should output the following result.

The largest dog weight is 200

Searching with Traverals Again

Continue to use the Dogs.csv data set to search for the lowest value in the maximum weight column. Modify the existing program that finds the largest weight, so that it finds the lowest weight instead. When you are done the program should output the following result.

The lowest dog weight is 7

Finding Outliers

Build a program that finds the outliers in a column. An outlier in this case is when a value in a column has a z-score that is greater than three or less than negative three. A z-score is calculated by taking the value in the column minus the column mean, all divided by the column standard deviation.

Begin by reading through the existing code and then getting the mean and standard deviation from the column. Then calculate the z-score and use an if block to decide if the value is an outlier. You should expect the program to output the following when it is functioning.

200.0 is an outlier.

Outliers Continued

Continue building a program that finds all the outliers in a column. In this program, add a counter variable for outliers. Then have the program output the number of outliers found. If no outliers are found, output a message that tells the user that no outliers were found. You should expect the program to output the following when it is working.

200.0 is an outlier.
1 outliers found.

Once you have a functioning program, search the other columns for outliers to test different outcomes by changing the parameter 9 to 8 in two different blocks. For example, column 8 has no outliers and produces the following output.

No outliers found.