1/143
Looks like no tags are added yet.
What is Data Science?
isn’t well defined, but incorporates elements of: exploratory data analysis, visualization, machine learning, statistics, and high-performance computing.
Hacking Skills + Math/Stats Knowledge =
Machine Learning
Math/Stats Knowledge + Substantive Expertise =
Traditional Research
Hacking Skills + Substantive Expertise
Danger Zone
Intersection of all three =
Data Science
Scientist worldview:
Scientists study the messy/complicated natural world (nothing is completely true or false)
Computer Scientist Worldview:
Computer scientists build clean, organized virtual worlds (everything is binary: true or false)
Scientist approach:
data-driven and discover
Computer Scientist approach:
algorithm-driven and invent.
Are Scientist comfortable with errors:
True
Are Computer Scientist comfortable with errors:
False
Computer Scientist often view data as simply stuff to run through a program:
True
Which of the following statements best reflects the difference between real scientists and computer scientists?
Scientists are data-driven, while computer scientists are algorithm-driven.
Genius shows in finding the right answer:
True
Wisdom shows in avoiding the wrong answer:
True
Sources of wisdom:
Experience, general knowledge, listening to others, and humility (learning from mistakes).
According to the lecture, while genius shows in finding the right answer, wisdom shows in:
Avoiding wrong answers
A good data scientist develops a curiosity about the domain/application they are working in:
True
What computer scientists do is create clever ways to encode and process information to solve problems.
True
Using binary representation on the 5 fingers of one hand, what is the highest number you can count to?
31
What is a programming language?
a set of vocabulary and rules that allow a human to communicate with a computer. Programs are written and executed sequentially.
Syntax:
The strict, predictable format/rules required for code to be translated.
Semantics:
The actual meaning, intent, or purpose of the code (which computers do not understand).
Compiled:
Translates source code into machine code prior to running.
Interpreted (e.g., Python):
Translates line-by-line during runtime; syntax/runtime errors are only caught when an incorrect line is executed.
In programming languages, what term refers to the actual purpose or meaning of the code, which the computer does not inherently understand?
Semantics
Why are errors in interpreted languages like Python typically caught only when the offending line is reached?
Translation to machine code occurs during runtime.
Variable:
A user-named reference to a specific memory address (place in memory).
Literal:
A fixed, definitive value directly assigned to a variable (e.g., 3, "hello").
Naming Multi-Word Variables:
Convention calls for camelCase or snake_case.
In computer programming, what is a variable?
A user-named reference pointing to a specific address in memory
Statically-Typed Languages:
Require the programmer to explicitly declare the data type in the source code ahead of time.
Data types provide ___ to the computer program
context
Python is classified as a dynamically-typed language because:
It infers the data type of a variable during execution rather than requiring explicit declaration.
How can variables have their data type changed manually?
type casting or “Casting”
Role of Data Types:
They provide context to the program, dictating which operations are valid on that piece of data.
Primitive types: Numeric
int (integers), float (decimal numbers), complex.
Primitive types: Sequence Types:
str (ordered collection of characters), list, tuple.
Other Primitives:
Boolean, Dictionary, Set.
Type Casting:
Manually converting a variable from one data type to another to enable operations specific to the new type (e.g., int(), float(), str()).
Type Errors:
Attempting an operation on an incompatible data type (e.g., concatenating a string with a raw integer) raises a TypeError.
Why are data types essential in a programming language?
They define the context of the data and specify which operations are permitted on it.
What error occurs if you try to perform an operation between two incompatible data types without type casting (e.g., concatenating a string with an integer)?
TypeError
type():
Returns the data type of the passed variable.
print():
Sends output to the console.
input():
Receives input entered by the user at the console
The value returned by input() is always a string (str), even if the user enters numeric characters.
True
What is the default data type of any value returned by the input() function in Python?
str
String:
An ordered sequence of characters, enclosed in single or double quotes.
Indexing Rules:
Positive indexing counts from the left, starting at 0.
Negative indexing counts from the right, starting with -1 for the last character.
Slicing uses [start : end]
In Python sequence indexing, which index value refers to the very last character of a string?
-1
Comments:
Text intended exclusively for human readers that is ignored by the Python interpreter.
How are single-line comments denoted:
Denoted by the hash symbol (#).
How are Multi-line comments denoted:
Enclosed using triple quotes (""" or ''').
What happens to commented lines of code when a Python script is executed?
They are completely ignored by the Python interpreter.
Boolean Literals:
The bool data type has only two values: True and False. They often act as "flags" indicating binary state changes.
Comparison Operators:
Compare two values and reduce to a boolean (==, !=, >, <, >=, <=).
Logical Operators: and:
Evaluates to True only if all inputs are True.
Logical Operators: or:
Evaluates to True if any input is True.
Logical Operators: not:
Reverses the boolean value (unary operator)
Which logical operator evaluates to True if at least one of its operand conditions is True?
or
if Statement:
Control structure that executes a block of code only if the specified condition is True.
else Statement:
Provides an alternative block of code that executes when the preceding condition evaluates to False
elif Statement:
Short for "else if". It is only evaluated if the preceding if or elif condition evaluated to False, creating a priority hierarchy.
In a Python if-elif-else construct, when is an elif condition evaluated?
Only if all preceding conditions in the chain evaluated to False
Four Primitive Collections:
List (list()), Tuple (tuple()), Set (set()), and Dictionary (dict()).
List Properties:
Ordered, changeable (mutable), and allows duplicate values.
Declared with square brackets ([]).
Can store elements of any data type.
Zero-indexed; attempting to access an index outside the valid range raises an IndexError.
Lists are considered the default "go-to" collection unless another specific collection behavior is needed.
What type of error is raised if a program attempts to retrieve an item at an index position that does not exist in a list?
IndexError
Which statement accurately describes a Python list?
Ordered, changeable (mutable), allows duplicates
Syntax Difference:
Methods use dot notation (listName.method()), while general functions wrap the collection (function(listName)).
Key List Methods append():
Adds an element to the end.
Key List Methods insert():
Adds an element at a specified position.
Key List Methods pop():
Removes an element at a specified position.
Key List Methods remove():
Removes the first item with the specified value.
Key List Methods clear():
Removes all elements from the list.
len():
Returns element count.
max(), min(), sum():
Aggregate operations on list elements.
in / not in:
Membership operators that return a boolean indicating whether an item exists in the collection.
What is the difference between the .remove() and .pop() list methods?
.remove() deletes an item by matching value, whereas .pop() deletes an item at a specified index.
Tuple Properties:
Ordered, unchangeable (immutable), and allows duplicate values.
Declared with parentheses (()).
Zero-indexed using square brackets ([]) for retrieval.
Values cannot be reset or modified after creation.
What are tuples used for:
Durability, data integrity, and security—used when values represent a constant sequence that must never be altered during program execution
What is the primary conceptual reason to use a tuple instead of a list in Python?
Tuples provide immutability, ensuring constant data cannot be modified accidentally.
Structure:
Organized into <key, value> pairs and declared with curly braces {key: value}.
Mutability & Ordering:
Dictionaries are ordered and changeable (mutable).
Key Uniqueness:
Duplicate keys are not allowed; each key maps to a single value.
Indexing & Errors:
Indexed by key using bracket notation (dict[key]). Trying to access a key that does not exist raises a KeyError.
Use Case:
Ideal as lookup tables to quickly fetch data associated with a unique key.
What error is raised when you attempt to retrieve a value from a Python dictionary using a key that does not exist?
KeyError
Which of the following statements about Python dictionaries is correct?
They are changeable, ordered collections of key-value pairs with unique keys.
Dictionary Methods: .keys():
Returns a view/list containing the dictionary's keys.
Dictionary Methods: .values():
Returns a view/list containing all the values.
Dictionary Methods: .items():
Returns a view/list containing a tuple for each key-value pair.
Dictionary Methods: .get():
Returns the value of a specified key.
Dictionary Methods: .pop(key)
removes the element with the specified key.
Dictionary Methods: .popitem()
removes the last inserted key-value pair.
Dictionary Methods: .setdefault():
Returns the value of the key; if the key does not exist, it inserts the key with the specified default value.
Dictionary Methods: .update():
Updates the dictionary with specified key-value pairs.
Dictionary Methods: .clear():
Removes all elements from the dictionary.
Which dictionary method returns key-value pairs as a list of tuples?
.items()
What is the behavior of the .popitem() method on a Python dictionary?
It removes the last inserted key-value pair.