2018-05-02

posted May 2, 2018, 6:00 AM by Konstantinovich Samuel   [ updated May 2, 2018, 6:05 AM ]
Goal: Changing the format of the data you work with

Do Now:

On a new sheet of looseleaf with your name date etc. on top.

Given a List of Lists of integers:
nums = [
[1,2,3],
[4,5,6],
[3,-1,8] ]
You will find a way to calculate the sum of all of the numbers in the 2D list. 
a-Before you write the command discuss:
    -What size lists should it work on? What minimum? What maximum?
    -Do the inner lists have to be the same size? Why/Why not?
b-Write a function to calculate the sum of all the numbers. (Collaborate, discuss)
def sumOfLists( data):
   ???

Classwork: 
Given a string in the format:  multiple lines of text, where each line has integers separated by commas. 

How would you break up this string to make it easier to find the sum of all of these numbers?
dataLarge = """1,2,3,4
6,7,8,9,10
12,0,-20,3"""

a- Before you write this command, agree with your neighbors, what format the data should be in.
b- Write a series of commands:
    1. Use this smaller data set to be able to write out your results
    data = """1,2,3
    4,5
    -3,8"""
    Phase 1: Breaking up into numbers
    2. On paper Write a series of reassignments (data = ???  or similar) 
       Next to each command Write what you expect the results of that command to be.
        You may write a loop to help you do this 
    3. Compare and collaborate with your neighbors on this. 
    Phase 2: Calculating the sum
    4. Agree on a command/set of commands that would find the sum of the new data format.


Discussion / Sharing:
-What format did you want the data in to accomplish your goal? Why? 
-What are the advantages/disadvantages of the different formats mentioned?

Remaining Time + Homework:
Attached is a csv file. Download this MOCK DATA. This is fake data to practice with!
Big goal-
  Make a website that displays this data in an HTML Table, including the average of the numerical columns.
Location:
 public_html/04data/mockdata.py 
  (also put the data file in the same directory)
Parts:
  a) Get a py file to display a simple (mostly blank) webpage to test.
  b) Read the data from the file into a string, and print it out plain text.
  c) Break up the data into parts and print that out plain text.
  d) Convert the data into an HTML Table and print that out.
Challenge: (will discuss tomorrow)
  e) Find the average of the numerical columns (loop through your data, and find the sum of each column first)
    Print out these calculations after the table.


ċ
MOCK_DATA.csv
(1k)
Konstantinovich Samuel,
May 2, 2018, 6:20 AM
Comments