# 1) Create a variable with a value of 2, and another one with a value of 3
x = 2
y = 3Creating Variables: - A variable can be set to any data type - You can name a variable anything - Except… it cannot start with a number, or contain periods
Basic Math Functions: - Addition: x + y - Subtraction: x - y - Multiplication: x * y - Division: x/y - Exponential: x ** y
# Add, multiply and divide your variables!
x + y5
x * y6
x / y0.6666666666666666
Data Types - Integers (‘int’): Whole numbers - Floats (‘float’): Decimals - Strings (‘str’): Sequences of characters surrounded by quotations - Booleans (‘bool’): True/False - Lists (‘list’): Collections of items surrounded by brackets - Dictionaries (‘dict’): Collections of items assigned to labels
# DO NOT REMOVE #
num1 = 5
num2 = 5.0
num3 = "5"
my_dict = {
'colors': ['red', 'blue', 'green'],
'numbers': [1,2,3],
'favorite food': 'pizza'
}
my_list = ["hey", 35]
# DO NOT REMOVE ## Find the types of each: num1, num2, num3, my_dict and my_list (hint: type())
type(num1), type(num2), type(num3)int
# Create a list of numbers from 5-10 and a dictionary with your favorite
# foods and favorite drinks
my_list2 = [5, 6, 7, 8, 9, 10]
my_dictionary2 = {
"favorite foods": ["pizza", "pasta"],
"favorite drinks": ["costco oat milk", "costco soy milk"]
}
my_list2[0], my_dictionary2["favorite foods"](5, ['pizza', 'pasta'])
Indexing: retrieving an element from a collection (such as a list of dictionary) - Remember it starts at 0!
# Retrieve the first element of my_list, and the color green from my_dict
my_list[1], my_dict["colors"][2](35, 'green')
Importing Data: - Data usually comes in the form of CSV’s (comma seperated values) - We usually look at structured data which is a big table - We can index it like a dictionary!
# Import data here, and show the "head"
from google.colab import drive
drive.mount('/content/drive')
import pandas as pd
pd.read_csv("/content/drive/MyDrive/Chocolate Sales.csv")| Name | Author | User Rating | Reviews | Price | Year | Genre | |
|---|---|---|---|---|---|---|---|
| 0 | Act Like a Lady, Think Like a Man: What Men Re... | Steve Harvey | 4.6 | 5013 | 17 | 2009 | Non Fiction |
| 1 | Arguing with Idiots: How to Stop Small Minds a... | Glenn Beck | 4.6 | 798 | 5 | 2009 | Non Fiction |
| 2 | Breaking Dawn (The Twilight Saga, Book 4) | Stephenie Meyer | 4.6 | 9769 | 13 | 2009 | Fiction |
| 3 | Crazy Love: Overwhelmed by a Relentless God | Francis Chan | 4.7 | 1542 | 14 | 2009 | Non Fiction |
| 4 | Dead And Gone: A Sookie Stackhouse Novel (Sook... | Charlaine Harris | 4.6 | 1541 | 4 | 2009 | Fiction |