Skip to content
Intermediate Python
Intermediate Python
Run the hidden code cell below to import the data used in this course.
# Import the course packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Import the two datasets
gapminder = pd.read_csv("datasets/gapminder.csv")
brics = pd.read_csv("datasets/brics.csv")Take Notes
Add notes about the concepts you've learned and code cells with code you want to keep.
Add your notes here
# Add your code snippets here
#index codes
#x.index('y')
#numpy codes
#np.array()
#Matplotlib codes
#plt.plot()
#plt.scatter()
#plt.xscale()
#plt.yscale()
#plt.title()
#plt.xticks()
#plt.text()
#plt.grid()
#plt.hist()
#plt.clf()
#plt.show()
#dictionaries
#a = {x:x1, y:y1,...}
#a.keys()
# Pandas
# x = pd.DataFrame(y)
# x = pd.read_csv('y')
#imprimir una columna como Panda Series
# print(x['y'])
#Imprimir una columna como Panda DataFrame
# print(x[['y']])
#imprimir varias columnas como pd DataFrame
#print(x[['y','z']])
#imprimir usando iloc y loc
#print(x.loc[:, ['y','z']])
#print(x.iloc[:,[1:3]])
#OPERADORES BOOLEANOS PARA NUMPY
#np.logical_or()
#np.logical_and()
#np.logical_not()
# IF, ELIF, ELSE
# if 'x' :
# then 'y'
# elif 'x' :
# then 'a':
# else :
# 'b'
#WHILE AND LOOP
#while 'x' = 1:
# print('y')
# x= x+1
#for 'x' in 'y':
#print('x')
#IMPRIMIR CON IN ENUMERATE
# for index, 'x' in enumerate('y')
# print(a)
#LOOP EN DICTIONARIOS
# for 'x','y' in 'a'.items():
# print('a')
#Loop en Numpy Array
# for 'x' in np.nditer('y') :
# print('a')
#LOOP en DataFrames
# for lab, row in 'x'.iterrows():
# print(lab)
# print(row)
# USANDO APPLY
# 'x'['y'] = 'x'['z'].apply('a')
# print('x')
#numeros RANDOM
# np.seed()
# np.random.rand()
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!".