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.
Use of the index function of the list to access the location of a value within the list
names = ['Albania', 'Syria', 'UK', 'Germany', 'Greece']
ind = names.index('Syria')
print(ind)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!".
#AND/OR/NOT OPERATIONS IN NUMPY AND PANDAS
data1 = []; data2 = []
data3 = np.logical_and(data1<10, data2>2)
np.logical_or(...)
np.logical_not(...)Iterate in a dictionary and numpy array
import numpy as np
country_data = {'afganistan':27, 'kenya': 33, 'albania': 4}
for k, v in country_data.items():
print(k, v)
item1 = np.array([[1, 3, 5, 7], [14, 22, 3, 8]])
for i in np.nditer(item1):
print(i)