This notebook is an exercise in the Data Visualization course. You can reference the tutorial at this link.


In this exercise, you will write your first lines of code and learn how to use the coding environment for the micro-course!

Setup

First, you'll learn how to run code, and we'll start with the code cell below. (Remember that a code cell in a notebook is just a gray box containing code that we'd like to run.)

ex0_run_code

The code cell below imports and configures the Python libraries that you need to complete the exercise.

Click on the cell and run it.

The code you just ran sets up the system to give you feedback on your work. You'll learn more about the feedback system in the next step.

Step 1: Explore the feedback system

Each exercise lets you test your new skills with a real-world dataset. Along the way, you'll receive feedback on your work. You'll see if your answer is right, get customized hints, and see the official solution (if you'd like to take a look!).

To explore the feedback system, we'll start with a simple example of a coding problem. Follow the following steps in order:

  1. Run the code cell below without making any edits. It will show the following output:

    Check: When you've updated the starter code, check() will tell you whether your code is correct. You need to update the code that creates variable one

    This means you need to change the code to set the variable one to something other than the blank provided below (____).

  1. Replace the underline with a 2, so that the line of code appears as one = 2. Then, run the code cell. This should return the following output:

    Incorrect: Incorrect value for one: 2

    This means we still have the wrong answer to the question.

  1. Now, change the 2 to 1, so that the line of code appears as one = 1. Then, run the code cell. The answer should be marked as Correct. You have now completed this problem!

In this exercise, you were responsible for filling in the line of code that sets the value of variable one. Don't edit the code that checks your answer. You'll need to run the lines of code like step_1.check() and step_2.check() just as they are provided.

This problem was relatively straightforward, but for more difficult problems, you may like to receive a hint or view the official solution. Run the code cell below now to receive both for this problem.

Step 2: Load the data

You are ready to get started with some data visualization! You'll begin by loading the dataset from the previous tutorial.

The code you need is already provided in the cell below. Just run that cell. If it shows Correct result, you're ready to move on!

Next, recall the difference between comments and executable code:

In the code cell below, every line is a comment:

# Uncomment the line below to receive a hint
#step_2.hint()
#step_2.solution()

If you run the code cell below without making any changes, it won't return any output. Try this now!

Next, remove the pound sign before step_2.hint() so that the code cell above appears as follows:

# Uncomment the line below to receive a hint
step_2.hint()
#step_2.solution()

When we remove the pound sign before a line of code, we say we uncomment the line. This turns the comment into a line of executable code that is run by the computer. Run the code cell now, which should return the Hint as output.

Finally, uncomment the line to see the solution, so the code cell appears as follows:

# Uncomment the line below to receive a hint
step_2.hint()
step_2.solution()

Then, run the code cell. You should receive both a Hint and the Solution.

If at any point you're having trouble with coming up with the correct answer to a problem, you are welcome to obtain either a hint or the solution before completing the cell. (So, you don't need to get a Correct result before running the code that gives you a Hint or the Solution.)

Step 3: Plot the data

Now that the data is loaded into the notebook, you're ready to visualize it!

Run the next code cell without changes to make a line chart. The code may not make sense yet - you'll learn all about it in the next tutorial!

Some questions won't require you to write any code. Instead, you'll interpret visualizations.

As an example, consider the question: Considering only the years represented in the dataset, which countries spent at least 5 consecutive years in the #1 ranked spot?

To receive a Hint, uncomment the line below, and run the code cell.

Once you have an answer, check the Solution to get credit for completing the problem and to ensure your interpretation is right.

Congratulations - you have completed your first coding exercise!

Keep going

Move on to learn to create your own line charts with a new dataset.


Have questions or comments? Visit the Learn Discussion forum to chat with other Learners.