Skip to content
1 hidden cell
Intermediate Python
Intermediate Python
Run the hidden code cell below to import the data used in this course.
1 hidden cell
Take Notes
Add notes about the concepts you've learned and code cells with code you want to keep.
Add your notes here
np.logical_or(x < 1, x > 3)
np.logical_and(x < 1, x > 3)
np.logical_or(x < 1, x > 3)
for index, height in ennumerate(fam):
print("index",str(index))
fam = [1.73, 1.68, 1.71, 1.89]
for index, height in enumerate(fam) :
print("person " + str(index) + ": " + str(height))
Loop over NumPy array
If you're dealing with a 1D NumPy array, looping over all elements can be as simple as:
for x in my_array :
...
If you're dealing with a 2D NumPy array, it's more complicated. A 2D array is built up of multiple 1D arrays. To explicitly iterate over all separate elements of a multi-dimensional array, you'll need this syntax:
for x in np.nditer(my_array) :
...
Two NumPy arrays that you might recognize from the intro course are available in your Python session: np_height, a NumPy array containing the heights of Major League Baseball players, and np_baseball, a 2D NumPy array that contains both the heights (first column) and weights (second column) of those players.Explore Datasets
Use the DataFrames imported in the first cell to explore the data and practice your skills!
- Create a loop that iterates through the
bricsDataFrame and prints "The population of {country} is {population} million!". - Create a histogram of the life expectancies for countries in Africa in the
gapminderDataFrame. Make sure your plot has a title, axis labels, and has an appropriate number of bins. - Simulate 10 rolls of two six-sided dice. If the two dice add up to 7 or 11, print "A win!". If the two dice add up to 2, 3, or 12, print "A loss!". If the two dice add up to any other number, print "Roll again!".
Current Type: Bar
Current X-axis: None
Current Y-axis: None
Current Color: None