1. Home
  2. Explore
  3. Computer Science
  4. Data Analysis with Python

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Data Analysis with Python

  • 133Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Analysis Foundations

What is data analysis, and what are its main aims?

133 questions

  1. 1

    What is data analysis, and what are its main aims?

    Model answer

    Data analysis is the process of inspecting, cleaning, transforming, and modeling data to discover useful information, draw conclusions, and support decision-making.

    Explanation

    The process turns raw data into evidence that can guide decisions.

  2. 2

    Why are gathering, cleaning, and transforming data often important early steps in analysis?

    Model answer

    Data from real sources may be incomplete or inconsistently structured, so it often needs to be prepared before it can be analyzed reliably.

    Explanation

    Preparation makes data more suitable for later statistical analysis and modeling.

  3. 3

    What does modeling data mean in the context of data analysis?

    Model answer

    It means representing real-world situations in information systems and using methods such as inferential statistics to look for patterns or models.

    Explanation

    Modeling helps analysts examine whether meaningful relationships or patterns arise from the data.

  4. 4

    How does data analysis turn data into information?

    Model answer

    It identifies patterns or anomalies that give raw data meaning, such as learning from purchase records that a product sells better on a particular day.

    Explanation

    A finding summarizes what the data indicates rather than merely listing individual records.

  5. 5

    Why should data analysts provide evidence and communicate their findings clearly?

    Model answer

    Reports and dashboards make findings understandable and provide evidence that can support decisions by other departments.

    Explanation

    Analysis is useful when its results can be interpreted and acted on by others.

  6. 6

    Why might different audiences need different reports from the same analysis?

    Model answer

    Departments and roles such as marketing, sales, accounting, and executives may need different views or levels of detail.

    Explanation

    The underlying information can be shared while its presentation is adapted to each audience.

  7. 7

    What distinguishes managed, closed data-analysis tools from open programming tools?

    Model answer

    Managed tools are vendor-provided products ready to use, while open tools combine programming languages with open-source libraries and other products.

    Explanation

    Excel and Tableau are examples of managed tools; Python, R, and Julia are examples of open tools.

  8. 8

    What is a main advantage of managed tools such as Excel or Tableau?

    Model answer

    They are generally easy to learn, and a company provides documentation, support, and ongoing product development.

    Explanation

    Vendor support and a ready-to-use interface can make these tools approachable.

  9. 9

    What is a main limitation of closed data-analysis tools?

    Model answer

    Their capabilities are limited to the scope of the product, so users may be unable to extend them beyond its boundaries.

    Explanation

    The tool’s features and integrations are determined by the product.

  10. 10

    What flexibility can programming languages offer for data analysis?

    Model answer

    They can be extended to handle varied tasks, such as accessing APIs with secret-key authentication or consuming data from cloud services.

    Explanation

    Libraries and code allow analysts to work beyond the built-in capabilities of a single product.

  11. 11

    How can learning a programming language support long-term career flexibility?

    Model answer

    Programming skills for processing data can transfer across tools and workplaces, rather than depending on expertise in one particular product.

    Explanation

    A general skill can remain useful even if a specific vendor or tool changes.

  12. 12

    What is a major disadvantage of using a programming language for analysis?

    Model answer

    It takes time to learn coding fundamentals, so it is usually more difficult to get started than with a point-and-click tool.

    Explanation

    The flexibility of programming comes with a learning investment.

  13. 13

    Why does the tutorial favor Python for data analysis?

    Model answer

    Python is described as readable and approachable, free and open source, supported by many libraries, and used by major institutions.

    Explanation

    These qualities contribute to Python’s broad capabilities and ongoing usefulness.

  14. 14

    How does the tutorial compare Python and R for data analysis?

    Model answer

    It favors Python as easier to start with and more general in its libraries, while noting that R has a large collection of statistical functions and can suit highly technical disciplines.

    Explanation

    The comparison presents both languages as useful, with different strengths.

  15. 15

    What roles do pandas, Matplotlib, and Seaborn serve in the Python data-analysis ecosystem?

    Model answer

    Pandas is used for data analysis and handling, while Matplotlib and Seaborn are used for visualizations.

    Explanation

    Together, these libraries support common stages of working with data in Python.

  16. 16

    What are the main stages of a typical data-analysis process?

    Model answer

    The process commonly involves collecting data, cleaning it, reshaping or transforming it, analyzing it for patterns, and communicating or acting on the results.

    Explanation

    Preparation precedes analysis, while reporting or further modeling follows it.

  17. 17

    What kinds of sources might provide data for an analysis?

    Model answer

    Data may come from a database, files in different formats, or a web API.

    Explanation

    The source can affect how much work is needed to collect and clean the data.

  18. 18

    Why might data from a database need less cleaning than data obtained through web scraping?

    Model answer

    A database under an organization’s control is more likely to be in a usable condition, whereas scraped data may require more tedious cleaning.

    Explanation

    The preparation burden depends partly on how and where the data was collected.

  19. 19

    What is the purpose of reshaping and transforming data before analysis?

    Model answer

    It prepares data for analysis by changing fields, merging tables, or combining information from multiple sources.

    Explanation

    The goal is to put the collected data into a useful form for the next steps.

  20. 20

    What does the analysis stage seek to identify in prepared data?

    Model answer

    It seeks patterns, trends, and anomalies, often using statistical analysis.

    Explanation

    Once data is clean and suitably structured, analysts can examine it for meaningful behavior.

  21. 21

    How might the next steps differ between a data-science project and a project focused on data analysis?

    Model answer

    A data-science project may proceed to machine-learning models, while a data-analysis project may focus on reports, communicating results, and supporting decisions.

    Explanation

    Both use analysis, but their intended outcomes can differ.

  22. 22

    Why is the real-world data-analysis process better described as a cycle than a straight line?

    Model answer

    Analysts often move back and forth between stages as they discover issues or need to revise earlier work.

    Explanation

    New findings can prompt renewed cleaning, transformation, or analysis.

  23. 23

    How does the tutorial contrast typical data scientists’ and analysts’ strengths?

    Model answer

    Data scientists are described as typically having stronger programming and mathematics skills, while analysts are described as having stronger communication, reporting, and storytelling skills.

    Explanation

    These are presented as common differences, not as strict boundaries between the roles.

  24. 24

    How can programming-based analysis handle large datasets differently from spreadsheet-style analysis?

    Model answer

    Instead of visually inspecting every record, analysts use structural and statistical summaries to understand the data and can process very large datasets efficiently.

    Explanation

    A visual reference becomes impractical as the number of records grows.

  25. 25

    Why can applying a formula to many spreadsheet rows be less efficient than using Python?

    Model answer

    Filling formulas across many rows in a spreadsheet can be slow, while an equivalent Python operation can process the data very quickly.

    Explanation

    The tutorial’s example contrasts spreadsheet processing with fast array-based computation in Python.

  26. 26

    What can summary statistics reveal about data before an analyst examines individual records?

    Model answer

    They can reveal typical values, ranges, unusual values, and possible errors, helping the analyst decide what to investigate further.

    Explanation

    For example, comparing a mean and median or noticing a negative profit can raise useful questions.

  27. 27

    How can an analyst check whether a provided cost value is consistent with the data?

    Model answer

    They can calculate a new cost from the relevant fields, such as order quantity multiplied by unit cost, and compare it with the provided cost.

    Explanation

    A disagreement may point to an error in the original data or data-entry process.

  28. 28

    How can analysts use filtering to investigate a subset of sales data?

    Model answer

    They can select records matching conditions such as a particular state, age group, or country, and then calculate a summary such as average revenue for that subset.

    Explanation

    Filtering focuses an analysis on records relevant to a specific question.

  29. 29

    How can adding a percentage to product prices illustrate the use of programming in analysis?

    Model answer

    A single operation can increase all prices by the same percentage, applying the change quickly across the data.

    Explanation

    The example demonstrates applying a transformation to many values without editing them one by one.

  30. 30

    What did the tutorial’s correlation example suggest about profit and other sales variables?

    Model answer

    Profit showed positive correlation with unit cost, unit price, and revenue, and negative correlation with order quantity in the example.

    Explanation

    Correlation plots were used to identify relationships worth investigating further, not to establish their cause.

  31. 31

    What are Jupyter Notebook and JupyterLab, and how are they related?

    Model answer

    Jupyter is a free, open-source ecosystem of tools; JupyterLab is an expanded interface for working with notebooks that includes features such as a file browser, terminals, and previews.

    Explanation

    JupyterLab builds on notebook-based work with a broader interface.

  32. 32

    Why use a Jupyter notebook for data exploration?

    Model answer

    It provides an interactive environment where users run commands and see their results immediately.

    Explanation

    This makes it useful for trying analyses and inspecting their outputs as work progresses.

  33. 33

    What is a Jupyter notebook made up of?

    Model answer

    It is made up of cells that can contain code, Markdown text, or raw content.

    Explanation

    Cells are the basic units for organizing and running notebook material.

  34. 34

    What is the difference between a code cell and a Markdown cell?

    Model answer

    A code cell runs programming instructions, while a Markdown cell formats and displays explanatory text.

    Explanation

    Markdown can include headings, emphasis, links, and other formatted content.

  35. 35

    How can a Markdown notebook support sharing analysis results?

    Model answer

    Notebook content can be formatted and exported as documents such as HTML or PDF reports.

    Explanation

    This lets analysts present both explanatory text and analysis outputs together.

  36. 36

    What do the execution numbers beside notebook cells indicate?

    Model answer

    They indicate the order in which cells were executed, even if the cells have since been moved.

    Explanation

    Execution numbers help distinguish the notebook’s visual order from its execution history.

  37. 37

    What are the two main Jupyter notebook interaction modes?

    Model answer

    The two modes are edit mode, for changing cell content, and command mode, for operating on cells.

    Explanation

    The same keystroke can have different effects depending on the active mode.

  38. 38

    How can a user switch between command mode and edit mode using the keyboard?

    Model answer

    Press Escape to enter command mode and Enter to enter edit mode for the selected cell.

    Explanation

    In command mode, cell actions are available; in edit mode, typed characters change the cell content.

  39. 39

    What do the A and B commands do in Jupyter command mode?

    Model answer

    A inserts a cell above the selected cell, and B inserts a cell below it.

    Explanation

    These commands add cells relative to the current selection.

  40. 40

    How can a user delete a selected cell in Jupyter command mode?

    Model answer

    Press D twice in quick succession.

    Explanation

    The two-key sequence deletes the currently selected cell.

  41. 41

    How can a user change a cell between Markdown and Python code?

    Model answer

    Use M to set the cell to Markdown and Y to set it to code.

    Explanation

    These shortcuts change the selected cell’s type while in command mode.

  42. 42

    How do Ctrl+Enter and Shift+Enter differ when running a notebook cell?

    Model answer

    Ctrl+Enter runs the cell and leaves it selected; Shift+Enter runs it and moves selection to the next cell.

    Explanation

    Shift+Enter is useful when executing cells sequentially.

  43. 43

    How can users cut, copy, and paste notebook cells with keyboard commands?

    Model answer

    Use X to cut, C to copy, and V to paste a cell.

    Explanation

    These commands let users move or duplicate cells without rewriting their contents.

  44. 44

    How can users undo a recent notebook action?

    Model answer

    In command mode, press Z to undo a recent action.

    Explanation

    The tutorial distinguishes this notebook command from the usual Ctrl+Z shortcut in other contexts.

  45. 45

    Why can Matplotlib visualizations be convenient in Jupyter notebooks?

    Model answer

    Notebook environments can display Matplotlib figures directly alongside the code that creates them.

    Explanation

    This avoids having to view every result in a separate terminal or application.

  46. 46

    What is NumPy primarily designed to do?

    Model answer

    NumPy is a library for numerical computation, especially efficient processing of numbers and arrays.

    Explanation

    Its scope is focused, but many higher-level Python data tools rely on it.

  47. 47

    Why can NumPy computations be faster than equivalent operations on ordinary Python lists?

    Model answer

    NumPy uses efficient numeric representations and optimized low-level operations on arrays, whereas ordinary Python values have more object overhead.

    Explanation

    These features can make a substantial difference when processing large amounts of data.

  48. 48

    Why does the tutorial say NumPy is important even though analysts may use it indirectly?

    Model answer

    Libraries such as pandas and Matplotlib rely on NumPy for numerical processing, so NumPy supports much of the broader data-analysis ecosystem.

    Explanation

    A library can be foundational even when users do not call it directly for every task.

  49. 49

    How do computers represent data at the lowest level described in the tutorial?

    Model answer

    They store and process data as binary bits, represented by ones and zeros.

    Explanation

    Numbers therefore need binary representations to be stored in computer memory.

  50. 50

    What is the role of RAM when a computer processes data?

    Model answer

    RAM holds data that the computer is actively processing, while a hard drive is used for longer-term storage.

    Explanation

    Data typically needs to be loaded into memory for active computation.

  51. 51

    How many distinct values can be represented using nnn bits?

    Model answer

    There are 2n2^n2n possible bit patterns, and for unsigned binary numbers these represent values from 000 through 2n−12^n - 12n−1.

    Explanation

    Each bit has two possible states, so the number of combinations doubles with every added bit.

  52. 52

    Why can an age column and a net-worth column require different numeric storage sizes?

    Model answer

    Their possible value ranges differ: age usually has a relatively limited range, while net worth may span much larger values.

    Explanation

    Choosing a suitable representation depends on the range of values the data must hold.

  53. 53

    Why can saving a small number as an ordinary Python integer use more memory than its binary value alone would require?

    Model answer

    Python integers are objects with additional overhead, not just a compact sequence of bits representing the number.

    Explanation

    This design supports Python’s high-level features but uses extra memory.

  54. 54

    How can NumPy help control the memory used for integer arrays?

    Model answer

    It allows the user to choose integer types with different bit widths, such as 8-, 16-, 32-, or 64-bit integers.

    Explanation

    A suitably small type can reduce storage when the data’s range permits it.

  55. 55

    Why does NumPy associate a data type with an array?

    Model answer

    A consistent type lets NumPy store array elements efficiently and apply optimized numeric operations.

    Explanation

    A numeric array cannot use the same efficient representation if its elements have arbitrary types.

  56. 56

    What is a key difference between a NumPy array and a Python list?

    Model answer

    A NumPy array has a consistent element type and is designed for efficient numeric computation, while a Python list can hold mixed types and is more general-purpose.

    Explanation

    The array’s more constrained representation enables more efficient processing.

  57. 57

    How does NumPy indexing relate to indexing in Python lists?

    Model answer

    NumPy arrays support zero-based indexing, slicing, negative indices, and steps in ways similar to Python lists.

    Explanation

    These familiar operations make it straightforward to select array elements.

  58. 58

    What is multi-index selection in a NumPy array?

    Model answer

    It selects several elements by passing their index positions together, returning the selected elements as a new NumPy array.

    Explanation

    For example, an array can be indexed with a list of desired positions rather than selecting each value separately.

  59. 59

    How do a NumPy array’s shape, number of dimensions, and size differ?

    Model answer

    Shape gives the length along each dimension, the number of dimensions counts the axes, and size gives the total number of elements.

    Explanation

    For example, a two-row, three-column array has shape (2,3)(2, 3)(2,3), two dimensions, and six elements.

  60. 60

    What is a vectorized operation in NumPy?

    Model answer

    It applies an operation to array elements directly, such as adding a scalar to every element, without requiring the user to write a loop.

    Explanation

    The operation is expressed at the array level and NumPy applies it across the elements.

  61. 61

    What does broadcasting allow NumPy to do?

    Model answer

    Broadcasting allows compatible arrays or an array and a scalar to participate in element-wise operations.

    Explanation

    For array-to-array operations, the shapes must be compatible for the operation to work.

  62. 62

    What is a Boolean array, and how can it be used to filter data?

    Model answer

    A Boolean array contains true or false values corresponding to elements; it can select elements where the corresponding value is true.

    Explanation

    A condition such as an array value being greater than a threshold can generate the Boolean array automatically.

  63. 63

    How can multiple conditions be combined to select NumPy array values?

    Model answer

    Boolean conditions can be combined with logical operations such as AND, OR, and NOT, then used to select matching elements.

    Explanation

    Combining conditions makes it possible to express more specific filters.

  64. 64

    What kinds of operations does NumPy provide for arrays and matrices?

    Model answer

    It provides operations such as sums, means, standard deviations, variances, and linear-algebra operations, including matrix products and transposition.

    Explanation

    Many of these operations can be applied across an array or along a chosen axis.

  65. 65

    What are pandas’ two main data structures?

    Model answer

    They are the Series and the DataFrame.

    Explanation

    A Series is one labeled sequence; a DataFrame organizes multiple columns and rows.

  66. 66

    What is a pandas Series?

    Model answer

    A Series is an ordered sequence of values associated with an index and backed by a NumPy array.

    Explanation

    Its index allows values to be identified by labels as well as by position.

  67. 67

    How is a Series both like a list and like a dictionary?

    Model answer

    Like a list, it is ordered and can be accessed by position; like a dictionary, its values can also be accessed by index labels.

    Explanation

    The Series combines ordered sequence behavior with labeled lookup.

  68. 68

    What happens to a Series index if the user does not provide one?

    Model answer

    Pandas gives it a default sequential index beginning at zero.

    Explanation

    A custom index can instead assign meaningful labels to the values.

  69. 69

    What is the difference between label-based and position-based Series selection?

    Model answer

    Label-based selection uses the index labels, while position-based selection uses the values’ sequential positions, commonly through iloc.

    Explanation

    A Series can retain positional access even after it is given custom labels.

  70. 70

    How does pandas label-based slicing differ from ordinary Python slicing?

    Model answer

    In pandas label-based slicing, the ending label is included; in ordinary Python slicing, the upper positional limit is excluded.

    Explanation

    Remembering this distinction prevents mistakes when selecting a range of labeled values.

  71. 71

    What is a pandas DataFrame, and how are its columns related to Series?

    Model answer

    A DataFrame is a labeled two-dimensional table, and each of its columns can be understood as a Series.

    Explanation

    This makes a DataFrame a useful structure for tabular data with named columns.

  72. 72

    What information does the DataFrame info method provide?

    Model answer

    It summarizes the DataFrame’s columns, data types, and counts of non-missing values.

    Explanation

    This makes it useful for quickly checking a dataset’s structure and missingness.

  73. 73

    What does the DataFrame describe method summarize?

    Model answer

    It gives descriptive statistics for numeric columns, including counts, means, standard deviations, minima, maxima, and selected percentiles.

    Explanation

    It offers a quick statistical overview without displaying every row.

  74. 74

    How do loc, iloc, and direct column selection differ for a DataFrame?

    Model answer

    loc selects rows by label, iloc selects rows by position, and direct selection such as df['population'] selects a column.

    Explanation

    These selection methods let users choose data by row label, row position, or column name.

  75. 75

    What type of object is commonly returned when selecting a single DataFrame row or column?

    Model answer

    A single selected row or column is commonly returned as a Series.

    Explanation

    The Series retains the associated labels from the DataFrame.

  76. 76

    How does Boolean filtering work with a pandas DataFrame?

    Model answer

    A condition produces a Boolean Series, which can be used to select the DataFrame rows whose corresponding values are true.

    Explanation

    For example, a condition can select only records where a numeric column exceeds a chosen threshold.

  77. 77

    How can a user remove rows or columns from a DataFrame?

    Model answer

    The drop method can remove specified row labels or column names.

    Explanation

    The axis setting can determine whether the operation applies to rows or columns.

  78. 78

    What does it mean that most pandas operations are immutable?

    Model answer

    An operation generally returns a new Series or DataFrame rather than changing the original object.

    Explanation

    To retain the result, assign it to a variable, including the original variable if replacement is intended.

  79. 79

    How can a new DataFrame column be created from existing columns?

    Model answer

    Apply an operation to existing columns and assign the resulting Series to a new column name.

    Explanation

    For example, dividing GDP by population produces a per-capita measure for each row.

  80. 80

    How do pandas Series and DataFrames support element-wise operations and alignment?

    Model answer

    Operations can be applied across values, and pandas aligns labeled Series and DataFrame data by matching their indices or column names.

    Explanation

    Label alignment allows values in separate objects to be combined according to their matching labels.

  81. 81

    How can an analyst identify missing values in pandas?

    Model answer

    Methods such as isna or isnull identify missing values; their opposites, notna or notnull, identify present values.

    Explanation

    The paired names in each case are synonyms and can be applied to Series or DataFrames.

  82. 82

    How can Boolean summation help count missing values?

    Model answer

    Summing a Boolean result from a missing-value check counts the true entries, because true values contribute one and false values contribute zero.

    Explanation

    This can provide a count of missing or non-missing values in a Series or column.

  83. 83

    What does dropna do, and why should its default DataFrame behavior be checked?

    Model answer

    dropna returns data with missing values removed; by default on a DataFrame, it drops rows containing at least one missing value.

    Explanation

    The default can remove more rows than intended, so users can adjust the axis or threshold behavior.

  84. 84

    How can the dropna threshold option affect which rows or columns are retained?

    Model answer

    A threshold specifies how many non-missing values a row or column must contain to be kept.

    Explanation

    This can be less restrictive than dropping every row or column that contains any missing value.

  85. 85

    How can fillna handle missing values?

    Model answer

    It can replace missing values with a chosen value, such as zero or a statistic like the mean.

    Explanation

    Filling values is useful when removing incomplete records is not appropriate.

  86. 86

    What do forward fill and backward fill do?

    Model answer

    Forward fill propagates the preceding valid value into later missing positions; backward fill propagates a following valid value into earlier missing positions.

    Explanation

    They fill gaps using neighboring observations rather than a fixed replacement value.

  87. 87

    How can forward or backward filling be applied along different directions of a DataFrame?

    Model answer

    The axis setting determines whether values are filled across rows or down columns.

    Explanation

    The fill direction matters because it determines which neighboring values supply replacements.

  88. 88

    What is the difference between missing data and an invalid value?

    Model answer

    Missing data has no recorded value, whereas an invalid value is present but does not meet the expected format or type, such as text in a numeric price column.

    Explanation

    The two problems require different checks and cleaning steps.

  89. 89

    Why can a value be valid as a number but invalid for a particular dataset?

    Model answer

    Its validity depends on the data’s domain; for example, an age of 170 is an integer but is implausible as a human customer’s age.

    Explanation

    Checking domain validity requires knowledge of what values make sense in the context.

  90. 90

    Why can domain-related data cleaning be harder than correcting a missing value or an obvious type error?

    Model answer

    The analyst needs enough subject knowledge to decide whether a value is plausible in the specific domain.

    Explanation

    A value that looks unusual may be legitimate in an unfamiliar field.

  91. 91

    How can an analyst inspect and correct inconsistent categorical values?

    Model answer

    They can inspect unique values or value counts, then use replacement rules to map inconsistent entries to the intended categories.

    Explanation

    For example, variations in how a category is recorded can be standardized.

  92. 92

    How might an analyst correct an implausible age caused by an extra zero?

    Model answer

    If the context supports that explanation, the analyst can correct the affected values, such as by dividing them by ten.

    Explanation

    A domain-based diagnosis is needed before applying a correction to avoid changing legitimate values.

  93. 93

    What must be decided before identifying duplicate records?

    Model answer

    The analyst must define which fields determine that two records count as duplicates and which duplicate occurrence, if any, to retain.

    Explanation

    Duplicate rules depend on the analysis and are not always obvious from the data alone.

  94. 94

    How does the duplicated method decide which repeated values to mark by default?

    Model answer

    It treats the first occurrence as not duplicated and marks subsequent occurrences as duplicates.

    Explanation

    The keep setting can instead preserve the last occurrence or mark all repeated occurrences as duplicates.

  95. 95

    How can duplicate detection be limited to selected DataFrame columns?

    Model answer

    Specify a subset of columns so that duplicate status is determined using only those fields.

    Explanation

    Two records may match on one field but differ on another field that matters to the analysis.

  96. 96

    How does drop_duplicates relate to duplicated?

    Model answer

    drop_duplicates removes rows identified as duplicates according to the selected fields and keep rule.

    Explanation

    Its duplicate-handling options follow the same general rules as duplicated.

  97. 97

    What are the pandas str, dt, and cat accessors used for?

    Model answer

    They provide methods for string, datetime, and categorical data, respectively.

    Explanation

    The accessor exposes operations suited to the type of values in a column.

  98. 98

    How can pandas string methods help clean text data?

    Model answer

    String methods can split, search, strip, or replace text, and some operations support regular expressions.

    Explanation

    These operations help standardize and restructure string values.

  99. 99

    What does pandas read_csv do?

    Model answer

    It reads comma-separated or similarly delimited text data into a DataFrame.

    Explanation

    Its options can control such details as headers, separators, column names, data types, and missing-value markers.

  100. 100

    How can read_csv handle a file that has no header row?

    Model answer

    Set the header option to indicate that no header should be inferred, then provide column names if needed.

    Explanation

    This prevents the first data record from being mistaken for column labels.

  101. 101

    How can a non-comma separator be handled when reading a text file?

    Model answer

    Specify the file’s actual separator, such as a greater-than sign, in the read method’s separator option.

    Explanation

    A delimited text file need not use commas even if it is being read with pandas’ CSV-reading functionality.

  102. 102

    How can a read operation treat particular strings as missing values?

    Model answer

    Provide those strings as missing-value markers so pandas interprets them as missing data.

    Explanation

    This can prepare data for consistent missing-value checks and cleaning.

  103. 103

    How can a CSV import specify column names, data types, and a date column?

    Model answer

    Use the read method’s options for column names, column types, and date parsing.

    Explanation

    Specifying these details can produce a more useful DataFrame at the point of import.

  104. 104

    Can pandas read a CSV file directly from a remote location?

    Model answer

    Yes. A remote file address can be passed to read_csv, which can retrieve and read the file.

    Explanation

    The data does not always need to be downloaded manually first.

  105. 105

    What is the relationship between pandas read and write methods for file formats?

    Model answer

    Many formats have a corresponding read method and write method, such as read_csv and to_csv.

    Explanation

    The write method can provide options for details such as including an index or choosing a separator.

  106. 106

    How does pandas read data from a SQL database?

    Model answer

    A SQL query and a database connection can be passed to a pandas SQL-reading function to return the results as a DataFrame.

    Explanation

    Database-specific connector libraries are needed, but the general pandas workflow is similar across supported databases.

  107. 107

    How does using pandas to read SQL compare with fetching query results manually?

    Model answer

    Pandas can put query results directly into a DataFrame, whereas a lower-level cursor workflow fetches results that may need additional conversion.

    Explanation

    The DataFrame is immediately usable with pandas analysis operations.

  108. 108

    What is the difference between reading a SQL query and reading a whole SQL table?

    Model answer

    A query-reading method executes a supplied SQL query, while a table-reading method can load a named table directly.

    Explanation

    The table-reading approach can be convenient when the task is simply to import an entire table.

  109. 109

    What does pandas to_sql do, and what should be considered if the target table already exists?

    Model answer

    It writes DataFrame data to a database table; the user should choose whether an existing table should cause an error, be replaced, or have data appended.

    Explanation

    Choosing the table-existence behavior helps avoid unintended overwriting or failed writes.

  110. 110

    How does pandas read Excel files with multiple worksheets?

    Model answer

    It can read a selected worksheet by name; if no sheet is specified, it reads the first worksheet by default.

    Explanation

    A DataFrame represents the data from one worksheet at a time.

  111. 111

    When might an Excel-file object be useful instead of reading a worksheet directly?

    Model answer

    It can be useful when inspecting workbook details such as worksheet names before selecting which sheet to read.

    Explanation

    This is helpful when the workbook contains several sheets and its structure needs to be explored.

  112. 112

    What should a user consider when importing Excel files into pandas?

    Model answer

    Excel reading may depend on additional libraries, and compatibility can vary with the user’s environment or spreadsheet format.

    Explanation

    Checking the required library and platform instructions can help resolve import problems.

  113. 113

    How does pandas read tables from HTML pages, and what can make the result messy?

    Model answer

    It can identify and parse HTML tables into DataFrames, but complex layouts, repeated headers, or cells spanning rows or columns may require cleaning.

    Explanation

    HTML tables are often arranged for people to read rather than for direct machine analysis.

  114. 114

    Why can parsing a table from a well-structured webpage be useful for quick analysis?

    Model answer

    It can provide data directly from a webpage without first locating and downloading a separate dataset.

    Explanation

    The approach is most effective when the webpage’s table is structured clearly.

  115. 115

    What role does Matplotlib play in Python data analysis?

    Model answer

    Matplotlib is a plotting library used to create visualizations such as line plots, scatterplots, histograms, and bar charts.

    Explanation

    Pandas plotting methods can also use Matplotlib to create figures.

  116. 116

    How does a static Matplotlib plot differ from an interactive charting tool such as Bokeh?

    Model answer

    A static plot is an image with limited interaction, while an interactive chart can let users zoom, move around, or inspect portions of the data.

    Explanation

    Interactive plots can help explore data; static images can be convenient for reports.

  117. 117

    What is one use of a box plot in data analysis?

    Model answer

    A box plot summarizes a distribution using the median and quartiles and can show potential outliers.

    Explanation

    It offers a compact way to inspect spread and unusual values.

  118. 118

    How does a histogram differ from a density plot?

    Model answer

    A histogram groups observations into bins, while a density plot represents the distribution as a smoothed curve.

    Explanation

    Both visualize distributions, but they present their shapes differently.

  119. 119

    What is the difference between Matplotlib’s global and object-oriented approaches?

    Model answer

    The global approach calls module-level functions that act on the current plot, while the object-oriented approach calls methods on explicitly referenced figure and axes objects.

    Explanation

    Explicit references make it clearer which plot or axes a command affects.

  120. 120

    Why can the object-oriented Matplotlib approach be easier to manage for figures with multiple plots?

    Model answer

    It keeps references to each axes, so commands can target a specific plot rather than relying on which plot is currently active.

    Explanation

    This makes the code’s intended destination clearer when figures contain several plots.

  121. 121

    What information can a scatterplot encode beyond the positions of its points?

    Model answer

    It can also encode additional variables through properties such as point size and color.

    Explanation

    These visual properties allow several dimensions of data to appear in one chart.

  122. 122

    How can visualizations assist with data cleaning?

    Model answer

    They can reveal unusual distributions or potential outliers that warrant checking against the data’s context.

    Explanation

    A visual anomaly is a reason to investigate, not proof that a value is incorrect.

  123. 123

    What is Python’s indentation rule for defining function and control-flow blocks?

    Model answer

    Python uses indentation to mark the contents of a function, conditional, or other block.

    Explanation

    The indentation is part of the language’s syntax, not merely a visual convention.

  124. 124

    How does Python’s dynamic typing affect variable assignment?

    Model answer

    A variable can be assigned a value without a separate declaration of its type, and the value’s type can vary during a program.

    Explanation

    Python determines the type from the value assigned.

  125. 125

    What are Python’s basic types for integer, decimal, text, Boolean, and absent values?

    Model answer

    They include int, float or Decimal, str, bool, and None for an absent value.

    Explanation

    Python also provides conversions between compatible types, such as converting a numeric string to an integer.

  126. 126

    What is the difference between a Python list and a tuple?

    Model answer

    Both are ordered sequences, but lists can be modified while tuples are immutable after creation.

    Explanation

    Immutability means a tuple’s elements cannot be added or removed after it is created.

  127. 127

    When is a Python dictionary useful?

    Model answer

    It is useful for mapping meaningful keys, such as email or age, to associated values.

    Explanation

    Key-based lookup avoids relying on the position of a value in a sequence.

  128. 128

    What is a distinctive property of a Python set, and when is it useful?

    Model answer

    A set stores unique values and supports fast membership checks, making it useful for testing whether a value is present.

    Explanation

    Repeated values do not appear as separate elements in a set.

  129. 129

    How does a Python for loop typically work?

    Model answer

    It iterates through the items of a collection, assigning each item to a loop variable in turn.

    Explanation

    This is the common Python approach to processing each element of a sequence or other collection.

  130. 130

    Why are while loops often discouraged when a for loop can do the same job?

    Model answer

    A while loop can continue indefinitely if its stopping condition is not handled correctly, while a for loop naturally iterates over a collection.

    Explanation

    Using a for loop is often clearer when the task is to process a known collection.

  131. 131

    How are Python functions defined, and what do they return if no return statement is given?

    Model answer

    Functions are defined with def; if no explicit return value is provided, the function returns None.

    Explanation

    A function call produces a return value even when the function does not explicitly specify one.

  132. 132

    How can Python handle an error without immediately stopping the program?

    Model answer

    A try and except block can catch an exception and allow the program to respond to it.

    Explanation

    Exception handling provides a way to manage operations that may fail.

  133. 133

    What is the practical difference between Python 2 and Python 3 for a new project?

    Model answer

    Python 2 was deprecated in 2020, so new work should use Python 3.

    Explanation

    Python 3 is the supported evolution of the language described in the tutorial.

1 of 133
Question 1 of 133

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent