Python for Data Analysis
- 119Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
- spaceFlip card
- KI knew it
- DI didn't know it
- ←Previous card
- →Next card
What is computer programming?
Computer programming is the process of giving a computer instructions to perform an action or a set of actions.
Or swipe the card
119 cards
What is computer programming?
Computer programming is the process of giving a computer instructions to perform an action or a set of actions.
What can guide the choice of a programming language for a task?
The project or problem being addressed can influence which programming language is selected.
How do data professionals use Python across the data workflow?
Python supports data work throughout the workflow, including exploring, cleaning, and visualizing data and building machine-learning models.
What is a transistor, and what two states can it occupy?
A transistor controls the flow of electricity through a circuit and can be on or off.
What does binary represent in computing?
Computers operate using binary, represented as ones and zeros, which correspond to sequences of on and off transistor states.
How do low-level and high-level programming languages differ?
Low-level languages are machine-oriented and often difficult to use; high-level languages use more human-friendly syntax and are generally easier to learn.
What is syntax in a programming language?
Syntax is the set of rules and structures that governs how instructions in a programming language are written.
What characteristics have made Python popular?
Python is a versatile, high-level language known for being relatively easy to learn and powerful. It is open source and supported by many libraries and a large user community.
What is a programming library, and why is it useful?
A library is a reusable collection of code that can save time by providing functionality for common tasks.
What is a Jupyter Notebook?
A Jupyter Notebook is an open-source web application for creating and sharing documents containing live code, formulas, visualizations, and text.
What is a cell in a Jupyter Notebook, and what does it enable?
Notebook cells divide code and its input/output into modular sections that can be organized, moved, added, deleted, and run individually.
What is Markdown used for in a Jupyter Notebook?
Markdown is a way to write formatted text in a coding environment or plain-text editor, including headings, lists, tables, and formulas.
What is object-oriented programming?
Object-oriented programming organizes code around objects, which can contain both data and code that operates on that data.
How are a class and an object related in Python?
A class is a data type that bundles data and functionality. An object is an instance of a class.
How do methods and attributes differ, and how are they accessed?
A method is a function associated with a class that typically performs an operation. An attribute is a named value associated with an object or class. Both are accessed with dot notation; methods use parentheses, while attributes do not.
What does a Python variable represent?
A variable is a named reference to a value stored in computer memory; it is not the value itself.
What three questions help guide the creation of a variable?
Before creating a variable, consider its name, data type, and starting value. Meaningful names help explain what the variable stores.
What is the difference between an assignment and an expression?
An assignment stores a value in a variable. An expression combines values, symbols, or variables and produces a result when evaluated.
What is dynamic typing in Python?
Python uses dynamic typing: a variable can refer to objects of different data types, and Python determines the type from the assigned value.
Why should a variable generally be initialized before it is used?
Most variables must be assigned or initialized before they are used, because they do not have default values or types.
How do you modify the value stored in a variable?
Reassign a value to the variable. Calling a conversion or other operation without assigning its result does not change the variable's stored value.
Why does cell execution order matter in a Jupyter Notebook?
In a notebook, cells run in an order that affects variable values. Rerunning an earlier assignment can replace a value created by a later cell.
What are key Python restrictions on variable names?
Use letters, numbers, and underscores; start with a letter or underscore; do not use spaces, special characters, or parentheses; and remember that names are case-sensitive.
What is a Python keyword, and can it be used as a variable name?
A keyword is a reserved word with a special purpose in Python, such as
for,in,if, andelse. Keywords cannot be used as variable names.Which names should be avoided when naming Python variables?
Avoid naming variables after reserved keywords or existing functions, such as
printorstr, to prevent errors and confusion.What is a string, and what does it mean that strings are immutable?
A string is a sequence of characters and punctuation, usually written between single or double quotation marks. Strings are immutable.
How do integers and floats differ?
An integer represents a whole number without a fractional part. A float represents a number with a decimal component.
What is Boolean data, and what values does a comparison produce?
Boolean data has two possible values, usually
TrueandFalse. Comparisons in Python produce Boolean results.How can you check an object's data type in Python?
The
typefunction reports an object's data type, such asstr,int, orfloat.How do implicit and explicit type conversion differ?
Implicit conversion happens automatically, such as converting an integer to a float in mixed integer-and-float arithmetic. Explicit conversion is requested by the programmer, using functions such as
int,float, orstr.Why can combining different data types cause an error, and what should you do when it happens?
Combining incompatible types can cause a
TypeError, such as trying to add an integer to a string. Inspect the error message to identify the cause and correct the code.What is a function in Python?
A function is a reusable body or chunk of code for performing a specific task.
What is the basic structure for defining a Python function?
Use the
defkeyword, followed by a function name and parentheses containing its parameters, then a colon and an indented function body.How do function parameters and arguments differ?
A parameter is a name in a function definition that receives input. An argument is the value or information supplied when the function is called.
What does indentation indicate in a Python function?
The function body is the indented code beneath the function definition. Its lines belong to that function, and the indentation must be consistent.
What does
returndo, and how does it differ from printing a result?A return statement sends a result out of a function so it can be stored, combined with other operations, or used later; it does not merely print the result.
What is code reusability?
Reusability means defining code once and using it many times rather than rewriting it for each use.
What is modularity in programming?
Modularity is organizing code into separate components that work together and can be reused in other programs.
What is refactoring?
Refactoring restructures code while preserving its original functionality.
What is self-documenting code?
Self-documenting code is written so its purpose is clear and readable, including through meaningful variable names and clear, concise expressions.
What is a Python comment, and how is it marked?
A comment is a human-readable note that Python ignores during execution. A
#marks the rest of that line as a comment.What is an algorithm?
An algorithm is a set of instructions for solving a problem or accomplishing a task.
How can comments help when designing a function to solve a complex problem?
Breaking a problem into small steps and outlining those steps with comments before coding helps clarify the solution and organize the function.
What is a function docstring, and what information should it contain?
A docstring is a string at the beginning of a function body that summarizes the function's behavior and explains its arguments and return value. It begins and ends with three quotation marks.
What are some benefits of writing clean, reusable, modular code?
Clean, reusable, and modular code can reduce errors and rework, improve collaboration, and help teams work and communicate more effectively.
What does a comparator do, and what six comparisons can Python comparators express?
A comparator compares two values and produces a Boolean result. Python comparators include greater than, greater than or equal to, less than, less than or equal to, equal to, and not equal to.
How do
=and==differ in Python?Use
==to test whether values are equal. A single=is used for assignment, not for an equality comparison.What do Python's
and,or, andnotoperators do?Logical operators connect conditions:
andis true only when both conditions are true;oris true when at least one is true; andnotreverses a condition's Boolean value.What is branching in a program?
Branching lets a program change its execution path according to conditions, commonly using
if,elif, andelsestatements.When does the body of a Python
ifstatement execute?An
ifblock runs only when its condition evaluates toTrue. Its body is indented beneath the condition.When does an
elseblock execute, and how is it aligned with itsif?elseruns when the precedingifcondition is false. It is aligned with its correspondingif, while its body is indented beneath it.What is
elifused for in conditional logic?elifchecks another condition when the preceding conditions were false. It avoids deeply nestedifandelsestatements and can be used for multiple comparison cases.What does the modulo operator
%return, and how can it help identify an even number?The modulo operator
%returns the remainder after division. For example, a number divisible by 2 has remainder 0 when divided by 2.Define a loop, an iteration, and an iterable.
A loop is a block of code that carries out iterations. An iteration is one execution of the block, and an iterable is an object whose elements can be looped over.
How does a
whileloop decide whether to continue?A
whileloop repeatedly executes its body as long as its condition is true, checking the condition again after each iteration.What must you do to help a
whileloop eventually stop?Initialize and update the loop-control variable so the condition eventually becomes false; otherwise, the loop may run indefinitely.
When is a
forloop especially useful?Use a
forloop to iterate over the elements of a sequence or other iterable, processing one element at a time.What sequence does
rangeproduce by default, and is its stop value included?rangeproduces a sequence of numbers that starts at 0 by default, increases by 1 by default, and stops before the specified stop value.What are the start, stop, and step parameters of
rangeused for?The three
rangeparameters are start, stop, and step. The start is included, the stop is excluded, and the step controls the increment between values.How should you choose between a
forloop and awhileloop?Use a
forloop when processing elements of an iterable, especially a sequence or dataset record. Use awhileloop when repeating until a Boolean condition changes.What does the
breakkeyword do inside a loop?A
breakstatement exits a loop immediately, allowing execution to continue after the loop.What does the
+=operator do?+=is a shorthand for adding a value to a variable and assigning the result back to it; for example,x += 1is equivalent tox = x + 1.What is string concatenation, and which operator performs it?
Concatenation joins two or more strings into one. In Python, the
+operator concatenates strings.How do you insert a space between strings when concatenating them?
Whitespace characters count as characters in a string. To place a space between concatenated strings, include a space in one string or concatenate a separate string containing a space.
Which arithmetic-style operations can and cannot be performed on strings?
Python can repeat a string with the
*operator, but it cannot subtract or divide strings.How does string immutability affect attempts to modify a string?
Strings are immutable, so their characters cannot be changed in place. To create a modified string, produce a new string and reassign it if you want the variable to refer to that result.
How can you include quotation marks within a string?
Use single quotes to enclose a string that contains double quotes, or double quotes to enclose one that contains single quotes.
What is an escape character, and what role does the backslash play?
A backslash is an escape character that changes how the following character or character sequence is interpreted, allowing special characters to be included as ordinary text.
What does
\nrepresent, and how can you display it literally?\nrepresents a new line in a string. To display the literal characters\n, escape the backslash.What is indexing, and what does zero-based indexing mean?
Indexing accesses individual items in an iterable by their position. Python uses zero-based indexing, so the first item is at index 0.
How do negative indices access items in a sequence?
A negative index counts from the end of a sequence:
-1refers to the last item and-2to the second-to-last item.How does Python slicing select a portion of a sequence?
A slice is a portion of a sequence. The syntax
sequence[start:stop]includes the start index and excludes the stop index.What do omitted start and stop indices mean in a Python slice?
In a slice, omitting the start defaults to the beginning of the sequence, and omitting the stop defaults to its end.
What does the string
indexmethod return, and what happens if it finds no match?The string
indexmethod returns the first position of a matching character or substring. If no match is found, it raises aValueError.How can you check whether a substring occurs in a string?
Use
into test whether a substring is present in a string; the result is a Boolean.What does the string
formatmethod do, and what are three ways to identify its placeholders?The
formatmethod inserts values into string placeholders. Values can be supplied by position, by named keywords, or by integer indices in the braces.How can string formatting control decimal precision and alignment?
Format specifications can limit decimal places, such as
.2ffor a float shown to two decimal places, and align output, such as>6to right-align within a width of six.What is a data structure, and what purposes does it serve?
A data structure is a collection of data values or objects, potentially containing different data types. It helps store, access, organize, categorize, and modify data.
What are the key properties of a Python list?
A list is an ordered, mutable collection that can contain elements of different data types and can include duplicates.
How are lists and strings similar and different?
Lists and strings are ordered sequences that support indexing and slicing and can contain repeated elements. Lists hold elements of any data type and are mutable; strings are sequences of characters and are immutable.
How do the list methods
appendandinsertdiffer?appendadds an element to the end of a list.insertadds an element at a specified index.How do the list methods
removeandpopdiffer?removedeletes a specified value and raises aValueErrorif the value is absent.popremoves an element at a specified index.What is a tuple, and how is it commonly created?
A tuple is an immutable, ordered sequence that can contain elements of different data types. It is commonly written with parentheses or created with the
tuplefunction.Can an existing tuple be modified in place?
A tuple's elements cannot be changed in place. To add or change information, create and assign a new tuple.
What is tuple unpacking?
Unpacking assigns the elements of a tuple to separate variables, allowing those variables to be used independently.
What is a dictionary, and how do its keys and values relate?
A dictionary is a collection of key-value pairs. A key provides access to its associated value.
What are two ways to create a Python dictionary?
Dictionaries can be created with braces, separating each key and value with a colon, or with the
dictfunction.What kinds of values can be used as dictionary keys?
Dictionary keys must be immutable; examples include strings, numbers, and tuples. Lists, sets, and dictionaries cannot be used as keys.
What are the key properties of a Python set?
A set contains unique elements and has no positional order for indexing or slicing. The set itself is mutable, while its elements must be immutable.
How can you create a set, and what is the empty-braces pitfall?
Use
set(iterable)to create a set from an iterable; duplicates are removed. Nonempty sets can also be written with braces, but empty braces create a dictionary, not a set.What do set intersection, union, difference, and symmetric difference return?
Intersection returns shared elements; union returns elements from either set; difference returns elements in one set but not the other; symmetric difference returns elements found in either set but not both.
What is a nested loop, and how does a list comprehension construct a new list?
A nested loop is a loop inside another loop. A list comprehension creates a new list from an existing iterable by placing the output expression before the
forclause.How do libraries or packages relate to modules?
A library or package is a reusable collection of code that can include related modules and documentation. A module is a Python file containing items such as functions, classes, and global variables.
What do import statements and aliases do?
An import statement loads an external library, package, module, or function into the computing environment. An alias provides an alternate name, such as
npfor NumPy orpdfor pandas.How do NumPy and pandas differ in their main purposes?
NumPy provides multidimensional arrays, matrices, and functions for scientific computation. Pandas, built on NumPy, provides tools for manipulating and analyzing tabular data.
What is vectorization, and why is it useful for data work?
Vectorization performs operations on multiple components of a data object in a single operation, often making computation faster and more memory-efficient than processing one item at a time in a loop.
What is an
ndarray?A NumPy array is an N-dimensional array, commonly called an
ndarray, and is NumPy's core data structure.What are important constraints when modifying a NumPy array?
NumPy arrays are mutable, but their elements must have a consistent data type. Adding an element changes the array's size only if a new array is created or assigned.
How can you check the element data type of a NumPy array?
Use an array's
dtypeattribute to inspect the data type of its contents.What do the NumPy array attributes
shapeandndimreport?The
shapeattribute reports an array's dimensions, such as rows and columns;ndimreports the number of dimensions.How can a two-dimensional NumPy array be created from Python lists?
A two-dimensional array can be created from a list of equal-length lists. Its inner lists correspond to rows, forming a table-like structure.
What does NumPy's
reshapemethod do?The
reshapemethod changes an array's arrangement into a specified shape, such as changing a two-dimensional array's row and column counts.How do pandas DataFrames and Series differ?
A DataFrame is a two-dimensional, labeled structure with rows and columns that can contain multiple data types. A Series is a one-dimensional, labeled array, often representing a DataFrame row or column.
How can you create a pandas DataFrame from Python data or a CSV file?
Use
pd.DataFrameto create a DataFrame from supported data such as a dictionary or NumPy array. Usepd.read_csvto read a comma-separated-values file into a DataFrame.How do pandas methods and attributes differ?
DataFrame and Series methods perform actions and use parentheses; attributes describe characteristics and do not use parentheses. Both are accessed with dot notation.
How do pandas column selection,
iloc, andlocdiffer?Use bracket notation with a column name to select a single column, a list of column names to select several columns, and
ilocto select by integer position.locselects rows and columns by label.How does Boolean masking filter a pandas DataFrame?
Boolean masking filters a DataFrame by aligning a Boolean Series with its rows: rows marked
Trueare retained, and rows markedFalseare excluded from the filtered view.Which operators combine conditions in pandas masks, and how should the conditions be grouped?
Use
&for AND,|for OR, and~for NOT in pandas Boolean conditions. Put each condition in parentheses.What does pandas
groupbydo, and what kinds of calculations can follow it?groupbygroups DataFrame rows according to values in one or more columns. You can then apply calculations such assum,mean,median,min,max, orcountto the groups.What does the pandas
aggmethod enable after grouping data?aggapplies one or more aggregation functions to grouped data, including built-in calculations and custom-defined functions.How does pandas
concatcombine DataFrames along axes 0 and 1?concatcombines DataFrames along an axis: axis 0 adds rows vertically, and axis 1 adds columns horizontally.What does each pandas join type—inner, outer, left, and right—retain?
mergejoins DataFrames using shared keys. An inner join keeps matching keys; an outer join keeps keys from both; a left join keeps all left keys; a right join keeps all right keys.What are the three defining principles of tidy data?
Tidy data has one variable per column, one observation per row, and one type of observational unit per table.
What is data tidying intended to accomplish?
Tidying structures a dataset to make it easier to manipulate, model, and visualize for analysis.
What are the main steps in a data-preparation project using unstructured files?
A data-preparation project may involve loading unstructured files, cleaning and structuring the data, and producing a tidy dataset suited to a business scenario.
Why document the steps and decisions made during a data project?
Documenting the steps taken and the reasoning behind decisions helps explain the work and thought process to future collaborators or hiring managers.
What transferable skills can a data professional highlight beyond knowledge of a particular tool?
Transferable skills include applying analytical thinking to business decisions, communicating work, managing datasets, and adapting skills across tools, organizations, and industries.
What should you consider when explaining technical work to stakeholders or interviewers?
Tailor technical explanations to the audience by considering their goals, existing knowledge, and what they need to know.
How can a data portfolio project help demonstrate professional skills?
A portfolio project provides a concrete example of a problem solved and can demonstrate coding proficiency and an approach to data challenges.

Ask anything
We've read this whole study set, so questions about it get the best answers.