Python Fundamentals


Figure 1

Value of 46371.45 with gdp_per_capita label stuck on it

Figure 2

Value of 46371.45 with gdp_per_capita label stuck on it, next to a value of 3.13 trillion with gdp label stuck on it.

Figure 3

Value of 45000.00 with gdp_per_capita label stuck on it, next to a value of 3.13 trillion with gdp label stuck on it.

Reading Tabular Data into DataFrames


Figure 1

'data' is a 3 by 3 numpy array containing row 0: ['A', 'B', 'C'], row 1: ['D', 'E', 'F'], androw 2: ['G', 'H', 'I']. Starting in the upper left hand corner, data[0, 0] = 'A', data[0, 1] = 'B',data[0, 2] = 'C', data[1, 0] = 'D', data[1, 1] = 'E', data[1, 2] = 'F', data[2, 0] = 'G',data[2, 1] = 'H', and data[2, 2] = 'I',in the bottom right hand corner.

Visualizing Tabular Data


Figure 1

A line graph showing the GDP of each country in Europe between 1952 and 2007. Unhelpfully, the dependant variable has been assumed to be the column headers, rather than the rows.

Figure 2

A line graph showing the GDP per capita of 5 European countries, from 1952 through to 2007.

Figure 3

Diagram illustrating how the axis keyword changes the axis along which the mean() function operates.

Figure 4

A line graph showing the change in the average GDP of European countries.)


Figure 5

A figure which contains three subplots, side-by-side

Figure 6

A figure with 3 subplots, each labelled with the statistic that they display.

Storing Multiple Values in Lists


Figure 1

veg is represented as a shelf full of produce. There are three rows of vegetables on the shelf, and each row contains three baskets of vegetables. We can label each basket according to the type of vegetable it contains, so the top row contains (from left to right) lettuce, lettuce, and peppers.

Figure 2

veg is now shown as a list of three rows, with veg[0] representing the top row of three baskets, veg[1] representing the second row, and veg[2] representing the bottom row.

Figure 3

veg is now shown as a two-dimensional grid, with each basket labelled according to its index in the nested list. The first index is the row number and the second index is the basket number, so veg[1][3] represents the basket on the far right side of the second row (basket 4 on row 2): zucchini

Repeating Actions with Loops


Figure 1

The plots of the min, max, and average GDP of countries in Europe, that we created earlier.

Figure 2

Loop variable 'num' being assigned the value of each element in the list odds in turn and then being printed

Analyzing Data from Multiple Files


Figure 1

Output from the first iteration of the for loop. Three line graphs showing the yearly minimum, maximum and average GDP over the years for the countries in the first dataset.

Figure 2

Output from the first iteration of the for loop. Three line graphs showing the yearly minimum, maximum and average GDP over the years for the countries in the second dataset.

Figure 3

Output from the first iteration of the for loop. Three line graphs showing the yearly minimum, maximum and average GDP over the years for the countries in the third dataset.

Making Choices


Figure 1

A flowchart diagram of the if-else construct that tests if variable num is greater than 100

Figure 2

C gets printed because the first two conditions, 4 > 5 and 4 == 5, are not true, but 4 < 5 is true. In this case only one of these conditions can be true for at a time, but in other scenarios multiple elif conditions could be met. In these scenarios only the action associated with the first true elif condition will occur, starting from the top of the conditional section. A flowchart diagram of a conditional section with multiple elif conditions and some possible outcomes. This contrasts with the case of multiple if statements, where every action can occur as long as their condition is met. A flowchart diagram of a conditional section with multiple if statements and some possible outcomes.


Creating Functions


Figure 1


Figure 2

Labeled parts of a Python function definition

Figure 3

Box plots of the distribution of bill sizes for different species of penguins

Errors and Exceptions


Defensive Programming


Figure 1

Graph showing three number lines and, at the bottom,the interval that they overlap.

Debugging


Command-Line Programs