Lecture 6
Rows
DATA 8
Summer 2017
Slides created by John DeNero (denero@berkeley.edu), Ani Adhikari (adhikari@berkeley.edu), and Sam Lau (samlau95@berkeley.edu).
Tables Review
Table Structure
Name | Code | Area (m2) |
California | CA | 163696 |
Nevada | NV | 110567 |
Label
Column
Row
Table Methods
Quick Check
The table students has columns Name, ID, and Score.
Write one line of code that evaluates to:
students.select('Name')
b) The largest score
students.column('Score').max()
students.select(0)
max(students.column('Score'))
Sort
Sorting Tables
Tables are ordered collections of rows
The sort method creates a new table with the same rows in a different order (the original table is unaffected)
The show method displays the first rows of a table
(Demo)
Lists
Lists are Generic Sequences
A list is a sequence of values (just like an array), but the values can all have different types
[2+3, 'four', Table().with_column('K', [3, 4])]
If you create a table column from a list, it will be converted to an array automatically
(Demo)
Take
Take Rows, Select Columns
The select method returns a table with only some columns
The take method returns a table with only some rows
(Demo)
Where
The Where Method
The where method specifies a column and a condition
It returns a new table with all rows satisfying the condition
(Demo)
Manipulating Rows