Skip to content

Dictionaries & Pandas

Learn about the dictionary, an alternative to the Python list, and the pandas DataFrame, the de facto standard to work with tabular data in Python. You will get hands-on practice with creating and maniplating datasets, and you'll learn how to access the infromation you need from these data structures.

# list
pop = [30.55,2.77,39.21]
countries = ["afghanistan", "albania", "algeria"]

#create dictionary using key:value pairs
world = {"Afghanistan":30.55,"Albania":2.77, "Algeria":39.21}

#the dictionary allows me to call for the value using the key. Much more intuitive and efficent then using an index.
print(world["Albania"])

Very useful in the data world.

#to create a dictionary

my_dict = {
   "key1":"value1",
   "key2":"value2",
}

#call on keys
dictionary_name.key

#call on value using key
dictionary_name['key']
Hidden output
# Definition of dictionary
europe = {'spain':'madrid', 'france':'paris', 'germany':'berlin', 'norway':'oslo' }

# Print out the keys in europe
print(europe.keys())

# Print out value that belongs to key 'norway'
print(europe['norway'])