Monthly Archives: March 2018

Spring 2018 R Open Lab: Exploratory Data Analysis

Mar 28

This week ‘s topic is Exploratory Data Analysis in R. The goal of the lab is to give attendants some ideas about what they can learn when they first have a data set in their hands and the corresponding approaches. The lab started with introduction of data frame’s concept and how to create one in R. Then, we talked about different ways to import data into R. After that, we learned ways to explore features of a data frame using the data set “diamonds.csv”. With the information we learned, we started to manipulate the data frame into our desired form by reordering and subsetting. We ended this lab with 2 simple practices of what we learned so far.

Here is the link to the script for this open lab:

https://drive.google.com/file/d/12ejSGZspc5_rBjDfvbu61H3lGdmYjAyf/view?usp=sharing

Here is the data set we used for this lab:

https://drive.google.com/file/d/19crfzpYAS3T0ZXaVxkWQVgk8dFbboFdf/view?usp=sharing

Thank you all for showing up. If you have further questions regarding topics covered in the material, please feel free to drop by during next week’s lab or email me or leave a comment.

See you all next week!

Python Open Labs: March 26, 2018

Over the past few weeks, students have been learning how to iterate through items – whether they may be in strings, lists, tuples, or dictionaries. Students have mainly been using for loops to grab the value of each item, and lots of progress has been in regards to writing them with little to no instruction.

In this blog post, I wanted to go over two different ways to write for loops that I presented in class. One method uses the loop to take on the literal value of an item, whereas the other method uses the loop to take on the index of the item.

Let’s say that we have a list:

lst = [1, 2, 3, 4, 5, 6]

If I wanted to iterate through the list such that my iterator takes on the literal value of the list, then I would write my for loop like this:

for item in lst:

>>>>print(item)

The output of this program would simply be:

1
2
3
4
5
6

If I wanted my for loop to instead take on the index value of each item within the list, then I would write my for loop like this:

for item in range(len(lst)):

>>>>print(item)

The output of the program would now be:

0
1
2
3
4
5

The only difference between this for loop and the previous one is the additional use of the keywords range and len, which allow the iterator to take on an item’s index value.

Note that using the for loop structure with these keywords also allow you to take on the literal value of the list when you index the list within the loop.

Here is example of what that looks like:

for item in range(len(lst)):

>>>>print(item, lst[item])

The output of this program is:

0 1
1 2
2 3
3 4
4 5
5 6

Writing for loops either way is acceptable, but it’s important to know which one might be most relevant to your program. If I were simply looking to add one to every item in the list and print its output, using the for loop without range or len is just fine. If I had multiple lists to iterate over that all happen to be the same length, I might want to incorporate the keywords to save time and efficiency in my program.

For instance, let’s say I had two lists that were of the same length.

animals = [“dog”, “bird”, “horse”]

nums = [2, 11, 19]

I would only need to iterate through one list to grab the values from both by using range and len.

Here is what that looks like:

for item in range(len(animals)):

>>>>print(animals[item], nums[item])

My output would look like:

dog 2
bird 11
horse 19

I hope you found this blog post about for loop structure and output helpful and are confident enough to know which ones to use in your own programs!

Navie Narula

Python Open Lab: Week 4

On March 5, we built on the lesson from week 3, and reviewed functions. Here is one of the problems you can try:

The full jupyter notebook is available for this lesson. Please comment, or send us an email and we can make this lesson (or any other lesson from the semester) available to you!