import pandas
pandas.DataFrame([[1,2,3], [4,5,6]], columns=["col1", "col2", "col3"])
import pandas as pd
pd.DataFrame([[1,2,3], [4,5,6]], columns=["col1", "col2", "col3"])
from pandas import DataFrame
DataFrame([[1,2,3], [4,5,6]], columns=["col1", "col2", "col3"])
# Assign a String
mystring = 'this is my string'
print(mystring)
# Assign an f string you can embed variables in this string by wrapping in {}
my_f_string = f'this is my f string with another string "df" {mystring}'
print(my_f_string)
# Assign a raw string
my_raw_string = r"Hello\n World"
print(my_raw_string)
Hello\n World
my_raw_string = "Hello\n World"
print(my_raw_string)
Hello
World
# Assign an integer
my_integer = 10
print(my_integer)
print(f"This is a variable of type: {type(my_integer)}")
10
This is a variable of type: <class 'int'>
# Assign a float variable
my_float = 10.6
print(my_float)
print(f"This is a variable of type: {type(my_float)}")
10.6
This is a variable of type: <class 'float'>
my_int_string = "5"
print(f"This variable starts out as a {type(my_int_string)}")
my_int_string_as_int = int(my_int_string)
print(f"but we can cast it to type of {type(my_int_string_as_int)}")
This variable starts out as a <class 'str'>
but we can cast it to type of <class 'int'>
#This however does not work!
my_int_string = "hello world"
my_int_string_as_int = int(my_int_string)
ValueError: invalid literal for int() with base 10: 'this is not a number!'
# Define a dictionary
my_dictionary = {
"myprop": "string",
"myprop2": 10
}
print(my_dictionary)
{'myprop': 'string', 'myprop2': 10}
print(my_dictionary['myprop2'])
10
my_dictionary['myprop2'] = 20
my_dictionary
my_dictionary['myprop3'] = "hello"
my_dictionary
del my_dictionary['myprop2']
my_dictionary
# Define a list
my_list = ["one", "two", "three"]
print(my_list)
['one', 'two', 'three']
# You can access an item by selecting the index - the index begins at 0
print(my_list[0])
one
# If you try to access an item that does not exist you will receive an error
print(my_list[3])
IndexError: list index out of range
# To add a new item to the list use append
my_list.append("four")
my_list.append("five")
print(my_list)
['one', 'two', 'three', 'four', 'five']
# to remove an item by its value use remove
my_list.remove("five")
print(my_list)
['one', 'two', 'three', 'four']
# To remove an item by its index use del
del my_list[3]
print(my_list)
['one', 'two', 'three']
my_list_2 = ["one", "one", "two", "three"]
my_set = {"rg", "rg", "gh"}
my_set
for item in my_list_2:
print(item)
one
one
two
three
for index, item in enumerate(my_list_2):
print(item)
print(index)
one
0
one
1
two
2
three
3
for key, value in my_dictionary.items():
print(key)
print(value)
myprop
string
myprop3
hello
for key in my_dictionary:
print(key)
myprop
myprop3
for value in my_dictionary.values():
print(value)
string
hello
for value in range(4):
print(value)
0
1
2
3
myexample = "a"
myexample2 = "c"
value3 = "e"
if (myexample == "a" and myexample2 == "b") or value3 == "d":
print("It's a and b together or we saw a d")
elif(myexample == "c"):
print("it was c!")
else:
print("It's not True")
It's not True
a = 6
b = 3
if a >= b:
print("a is greater or equal to b")
else:
print("b is greater than a")
a is greater or equal to b