# Chapter6.py # 1/2 VS Code # 1/2 Jupyter -> install the Jupyter Extension # single instances of variables and data types -> Level 1 ''' bit 0,1 8 bits -> byte 'A' 01000001 'B' 01000010 'C' 0100000011 char [a-zA-Z0-9]specials -> 'Bob' string ['B','o','b] int 1 -> 00000001 2-> 00000010 3-> 00000011 [64,32,16,8,4,2,1] 1000010 -> 66 float 10.25 complex 1Ex10 datetime bool True/False ''' # Collections of independent variables -> Level 1 lists,tuples and dictionaries | Level 2 - sets # Bob Joe Mary | Bob 21 True # multiple independent elements -> Collection ''' Lists [] -> indexed, CRUD, mutate a list element, duplicates, len(5)->[0-4] Sets {} -> !indexed, !dups, !sorted, CRUD Tuples () -> positionalID[1-5], immutable, dups, len(5)->[0-4] return arg1,arg2,arg3 -> (param1,param2,param3) Dictionaries/Maps {key: value} 'Sets of key/value pairs' -> key, value { fName: Bob, lName: Bob }, {fName: Mary, lName: Smith, age: 21 } ''' # Dimensional data frames -> Level 3 1 dim -> 7 dim # pandas, numpy -> data analysis # seaborn, matplotlib -> plotting ''' 1 Dim -> Series -> col[fname] -> value(Bob) 2 Dim -> dataFrame -> row/col -> value 3 Dim -> p1 -> row/col -> value 4 Dim -> p2,p1 -> row/col -> value ... 7 Dim -> p5,p4,p3,p2,p1 -> row/col -> value single pivot -> pivot one dim at a time matrix -> 2 dim to pivot from "cross-tab or cross-pivot" nested pivots -> p2->p1->row/col aggregate pivots -> sum,min,max,count,avg,dev,... time-based pivots -> pivoting based on datetime calculated pivots -> %,running sums,... ''' # Examples of Lists, Tuples (chapter 6) # Contacts -> List of Contacts by full name # Contact -> fullname # fullname -> firstname, lastname # List [] contacts = [] # contacts = ['Bob Smith','Mary Jones', ...] def userInputs(): firstName = input("Enter first name: ") lastName = input("Enter last name: ") return firstName, lastName # Create contact 1 firstName, lastName = userInputs() contact1 = firstName.title().strip() + ' ' + lastName.strip().title() print(contact1) # Bob Smith -> contact1 # Call contact1 and append to the end of the contacts list print(contacts) # This is what the list looks like BEFORE the contact1 append [] contacts.append(contact1) print(contacts) # ['Bob Smith'] # Create contact 2 firstName, lastName = userInputs() contact2 = firstName.strip().replace(' ','').title() + ' ' + lastName.title().strip() print(contact2) # Jane Doe -> contact2 # Call contact2 and append to the end of the contacts list print(contacts) # This is what the list looks like BEFORE the contact2 append ['Bob Smith'] contacts.append(contact2) print(contacts) # ['Bob Smith','Jane Doe'] # Tuples() ccNum = input("Enter CC Number: ") ccExp = input("Enter Exp: (mm/yy): ") ccCVC = int(input("Enter CVC Code: ")) creditCardInfo = (ccNum, ccExp, ccCVC) # (str,str,int) print(creditCardInfo) # Tuple # convert to list ## tuple = list(tuple) creditCardInfo = list(creditCardInfo) print(creditCardInfo) # List [] # do whatever to mutate the list ### stuff here ccNum = input("Enter UPDATED credit card number: ") creditCardInfo[0] = ccNum print(creditCardInfo) # List [] ### using the list object # convert to tuple ## list = tuple(list) creditCardInfo = tuple(creditCardInfo) print(creditCardInfo) # ()