# myFunctions.py def fullName(): # Ask the user for their first and last name. firstName = input("Enter your first name: ") lastName = input("Enter your last name: ") # Join the first and last name to a full name. fullName = f"{firstName} {lastName}" # Print the full name # print(fullName) return firstName, fullName # bob smith ''' myfirstName, myfullName = fullName() print("First name: " + myfirstName) print("Full Name: " + myfullName) ''' def cartTotal(taxRate, subTotal, shipping): # method 1 use the passed params total1 = subTotal + (subTotal * taxRate) + shipping # method 2 declare local var in scope v_subTotal = subTotal v_taxRate = taxRate v_shipping = shipping total2 = v_subTotal + (v_subTotal * v_taxRate) + v_shipping return total1, total2 # Report 1 def report1(): print("=== Report 1 for x in ys from list report ===") # Page 23 firstNames = ["Bob","Mary","Joe","Sally"] # List # for x in ys ## x is the local variable in the scope ## ys is the data set or range of values for firstName in firstNames: print(f"Contact First Name: {firstName}.") # Report 2 def report2(): print("=== Report 1 pandas dataframe using for x in ys ===") # read the data source ## csv import csv filename = "contacts.csv" with open(filename, mode="r") as file: reader = csv.reader(file) next(reader) # next skips the current row or iterator contacts = [] # outside list for row in reader: contacts.append(row) print(contacts) import pandas as pd # Chapter 10 df_contacts = pd.DataFrame(contacts) print(df_contacts) # DataFrame with a label example List Set customers = { "FirstName": ["Mark", "Maria", "Michael"], "Age": [21,32,45] } # customers df_customers = pd.DataFrame(customers) print(df_customers) # iloc[] notation int # loc[] notation str row_index1 = df_contacts.iloc[1] print(row_index1) row_label1 = df_contacts.loc[1] print(row_label1) # Loop thru the Series label iloc[0] or loc["FirstName"] print("=== First Name Series ===") firstName_Series = df_customers["FirstName"] for name in firstName_Series: print(name) col_id = int(input("What Series by indexid do you want to query?: ")) # loop using iloc[col_id] for col_value in df_contacts.iloc[:,col_id]: print(col_value) # Append a new row to the customers dataframe # Ask for the new dataframe rows data form_firstname = input("Enter a new first name: ") form_age = int(input("Enter customers age: ")) row_new = { "FirstName": form_firstname, "Age": form_age } df_customers = df_customers.append(row_new, ignore_index=True) print(df_customers) # Export the new dataframe to Excel using the to_ function sheetName = "ReplaceDateTime" df_customers.to_excel("new_contacts.xlsx", sheet_name=sheetName, index=False ) # Anaysis 1 def analysis1(): print("=== Plot data with matplotlib")