Python Lists and Pandas Dataframes

Mar 11, 2015 • Johan Hjelm

The first MCQ relates to the introductory (intermediate) lesson on Python programming from the v 5.2 lessons: 01-intro-python

You have a Pandas dataframe (assigned to the variable df) with the following data:


Which of the following code snippets will return the temperature and rainfall of rows 2 and 3?

  1. df[['temperature','rainfall']][1:3]
  2. df['temperature', 'rainfall'][1:3]
  3. df.iloc[1:3]
  4. df.iloc[1:3,1:2]

The second MCQ relates to the v 5.3 novice Python lesson and focuses on Python lists, which I also used for the concept map exercise.

You have the following list: myList = [42, 1, 0, 'moon']. What output does the following code generate:

print myList[1], myList[-1]
  1. 42, 'moon'
  2. 1, 'moon'
  3. 0, 42
  4. 0, 1


Answer 1 should diagnose whether the student has understood that .reverse() changes myList and should indicate whether the student has picked up on that Python starts numbering with 0, and not 1.

Answer 2 is intended to distinguish between cases where the student understands how the numbering of elements works and what the index -1 refers to, but that it has not understood how the .reverse() method works

Answer 3 is the correct answer

Answer 4 is to diagnose whether the student has understood how .reverse() works but not which element the index -1 refers to.