Welcome to DS2000 CS Practicum 7!
The data that we will be using comes from Copenhagen Networks Study and it describes communication patterns between pairs (dyads) of students. Remeber:
Each row is one dyad.
the 0th column corresponds to how long they spoke on the phone,
The 1st column corresponds to how many text messages that dyad exchanged in a month,
the 2nd column describes the gender of the dyad: 0 if both are male, 1 if both are female, 2 if one is male and the other female. Note that in this data there are no proper indicators for non-binary genders.
You might notice that some of the values are negative. This doesn't mean that somebody talked on the phone for a negative number of seconds. They appear like this becase I modified the original data by taking a logarithm to the value, multiplying by a scaling factor, and shifted by an offset so they fit nicely on the screen. Later we will learn how to work with the original data and still make it look good.
Exercise 1: Loading the data
Download the practicum_07.py and the dyads.csv files.
main()function implement loading the
dyads.csvfile into three lists, based on the value of the gender column. Do it using only one loop, reading through the file once, not with separate loops for each gender combination. > Show hint There should be 109 male dyads, 17 female dyads, and 38 mixed gender dyads. Make sure that your lists are of these lengths.
Exercise 2: Making a bar chart
In this exercise we will make a bar chart that shows the numbers of different genders of dyads with different colors: blue for men, green for women, and red for mixed dyads. This is what the final product will look somewhat like this:
We will build two functions to achieve this goal:
rect(x, y, width, height, color)that draws just one rectangle with the lower left corner at the coordinates of
ywith the specified
heightand if fills it with specified
color. Before going to the next function, make sure that this one works with different input arguments! > Show hint
bar(data)that takes a list of values (in our case it's three values but make sure your code works with a different number of values too!), and draws one rectangle per value, side by side with the
SPACINGbetween them of 5, and colors cycling through the
COLORSlist specified on top of the file (i.e. if there are four values, the fourth rect will be blue again). In your
main()function make a list of counts of dyads and call the
barfunction with that list as an argument. Your plot should look like the one on the screen shot.
Exercise 3: Making a scatter plot
In this exercise we will make a scatter plot that shows the relation betweenthe time spent talking on the phone and the number of exchanged messages for each dyad, depending on the gender. The final result will look like this, with one dot per dyad and colors denoting gender combination of the dyad:
scatter(points, color)function. that takes a list of points and for each leaves a stamp at point, point with a given color. > Show hint In your
main()function comment out the call to the
barfunction and instead call the
scatterfunction three times with different colors, one for each gender combination (one for each list). In the comments leave your answers to these questions:
what does it mean that one point is more to the right than another on this scatter plot?
what does it mean that one point is higher than another on this scatter plot?
what is the gender combination of a dyad that spent most time talking on the phone?
what is the gender combination of the dyad that sent most messages? Is it the same dyad as with most time on the phone?
if we see that a dyad mostly texts and hardly talks on the phone can we have a reasonable guess at their gender combination?
if we see that a dyad talks on the phone and messages a lot, can we have a reasonable guess at their gender combination?