1. Home
  2. Explore
  3. Computer Science
  4. Pandas for Data Analysis

Study methods

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

Pandas for Data Analysis

  • 73Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: DataFrame Fundamentals
In pandas, the info method summarizes a DataFrame's index, columns, data types, and non-null entries, while
reports its row and column dimensions.

73 questions

  1. 1
    In pandas, the info method summarizes a DataFrame's index, columns, data types, and non-null entries, while
    _____
    reports its row and column dimensions.
    Hint

    Think of the attribute that returns a pair of dimensions.

    Answer

    shape

    Explanation

    The shape attribute gives the number of rows and columns; info provides a fuller structural summary.

  2. 2
    When a DataFrame uses each English word as its index, selecting a particular word by its label is done with
    _____
    .
    Hint

    This label-based selector can retrieve a row by its index value.

    Answer

    loc

    Explanation

    The loc method selects rows by index label, so a word used as an index can identify its row.

  3. 3
    Selecting a single row with loc usually returns a vertical
    _____
    rather than a horizontal DataFrame row.
    Hint

    It is pandas' one-dimensional labeled data structure.

    Answer

    Series

    Explanation

    A single selected row is represented as a Series, with the column names serving as its index.

  4. 4
    To retrieve just one column while selecting a row with loc, provide the index selection and the
    _____
    selection.
    Hint

    This limits the returned data to a named field such as value.

    Answer

    column

    Explanation

    loc accepts row labels or conditions and, optionally, column labels to restrict which fields are returned.

  5. 5
    The DataFrame method that provides summary statistics such as mean, standard deviation, minimum, and maximum is
    _____
    .
    Hint

    Its name suggests giving a statistical overview of the data.

    Answer

    describe

    Explanation

    describe returns summary statistics for numeric columns, including count, mean, standard deviation, minimum, and maximum.

  6. 6
    To find the greatest value in a numeric Series, call its
    _____
    method.
    Hint

    It is the statistical method for obtaining the largest value.

    Answer

    max

    Explanation

    The max method returns the maximum value in a Series or, when applied to a DataFrame, for each applicable column.

  7. 7
    For a numeric Series, the statistical method that returns its most frequently occurring value is
    _____
    .
    Hint

    It names the measure of central tendency based on frequency.

    Answer

    mode

    Explanation

    The mode method returns the value or values that occur most often.

  8. 8
    To see how often each distinct value occurs, use the Series method
    _____
    .
    Hint

    This method produces a frequency ranking, not just a single most-common value.

    Answer

    value counts

    Explanation

    value counts reports the frequency of each distinct value, making it useful for ranking common values.

  9. 9
    In the English-words dataset, character count was calculated as the
    _____
    of each word.
    Hint

    Count how many characters the word contains.

    Answer

    length

    Explanation

    The character count column represents the length of each word.

  10. 10
    To create a word's value in the example dataset, the individual character values were
    _____
    .
    Hint

    The word's total was obtained by combining the values of its letters.

    Answer

    added

    Explanation

    Each character was assigned a value, such as A being one and B being two, and the character values were added to produce the word's value.

  11. 11
    A loc selection can take one index label, a list of labels, or a Boolean
    _____
    indicating which rows to select.
    Hint

    It contains true and false values corresponding to rows.

    Answer

    array

    Explanation

    loc supports a single label, multiple labels, or a Boolean array that marks rows for inclusion.

  12. 12
    A condition such as value equals 319 creates a Boolean array; rows whose condition is true are retained by
    _____
    .
    Hint

    This selector applies label-based and Boolean-mask selection.

    Answer

    loc

    Explanation

    The Boolean mask can be passed to loc to select rows satisfying the condition.

  13. 13
    Summing a Boolean Series in pandas counts the number of
    _____
    values because true is treated as one.
    Hint

    A true value contributes one to the sum.

    Answer

    true

    Explanation

    Boolean values act like zeros and ones in a sum, so summing a condition counts matching rows.

  14. 14
    In a pandas Boolean selection, the ampersand operator combines conditions with logical
    _____
    .
    Hint

    Both conditions must be satisfied for a row to be selected.

    Answer

    and

    Explanation

    The ampersand combines Boolean masks element by element as an AND operation.

  15. 15
    To select rows matching either of two Boolean conditions, combine the masks with the vertical bar, which represents logical
    _____
    .
    Hint

    A row can match the first condition, the second, or both.

    Answer

    or

    Explanation

    The vertical bar combines Boolean masks element by element as an OR operation.

  16. 16
    When a pandas query refers to a column name containing spaces, surround the column name with
    _____
    .
    Hint

    These are the marks commonly used around inline code in Markdown.

    Answer

    backticks

    Explanation

    The query method uses backticks around column names containing spaces so it can parse them correctly.

  17. 17
    In a pandas query, prefix an external Python variable with the
    _____
    symbol to distinguish it from a column name.
    Hint

    This symbol is used to refer outside the query expression.

    Answer

    @

    Explanation

    Within query, column names are interpreted as columns by default; the at symbol references a variable from the surrounding scope.

  18. 18
    When combining complex Boolean conditions, parentheses help ensure the intended order of
    _____
    .
    Hint

    They control which parts of an expression are evaluated together first.

    Answer

    operations

    Explanation

    Parentheses make the desired grouping explicit, especially when combining AND and OR conditions.

  19. 19
    The pandas method presented as a concise alternative for expressing simple conditions in a string-like form is
    _____
    .
    Hint

    It lets you write conditions using column names in an expression.

    Answer

    query

    Explanation

    The query method is a shorthand for filtering with straightforward conditions; loc remains useful for more flexible Boolean-mask selection.

  20. 20
    In the Pokémon data, a Boolean column such as legendary can itself be passed to loc as a
    _____
    for selecting rows.
    Hint

    It indicates which rows are included using true and false values.

    Answer

    mask

    Explanation

    Because legendary is already Boolean, it can directly serve as a mask to select legendary Pokémon.

  21. 21
    The logical negation operator can invert a Boolean mask to select Pokémon that are
    _____
    legendary.
    Hint

    It reverses true and false values in the mask.

    Answer

    not

    Explanation

    Negating the legendary Boolean Series selects rows where the legendary status is false.

  22. 22
    To count the Pokémon whose attack is greater than 150, one can select matching rows and inspect the result's
    _____
    .
    Hint

    Its row dimension gives the number of matches.

    Answer

    shape

    Explanation

    The shape of the filtered DataFrame reveals how many Pokémon met the attack condition; summing the Boolean condition also counts them.

  23. 23
    A Pokémon with speed 10 or less satisfies a condition written as speed less than or equal to
    _____
    .
    Hint

    This is the threshold specified for slow Pokémon in the activity.

    Answer

    10

    Explanation

    The inclusive condition retains Pokémon whose speed is 10 or any smaller value.

  24. 24
    To find a Pokémon with both type one equal to fire and type two equal to flying, combine the two conditions with logical
    _____
    .
    Hint

    Both type requirements must hold for the same Pokémon.

    Answer

    and

    Explanation

    An AND condition selects rows only when both the primary-type and secondary-type conditions are true.

  25. 25
    To find Pokémon that have poison in either type field, combine the type one and type two conditions with logical
    _____
    .
    Hint

    A match in either field is sufficient.

    Answer

    or

    Explanation

    An OR condition retains Pokémon whose type one or type two is poison.

  26. 26
    The is in method can express that a generation belongs to a chosen set, avoiding a longer chain of equality tests joined by
    _____
    .
    Hint

    It links alternative possibilities in a Boolean expression.

    Answer

    or

    Explanation

    Using is in with a collection of generations is a concise way to test membership instead of writing repeated OR conditions.

  27. 27
    To identify the most powerful Pokémon under a numeric measure such as total, sort the values with ascending set to
    _____
    .
    Hint

    This places the largest values at the beginning.

    Answer

    false

    Explanation

    Descending sorting places the highest total or other numeric value first, making the leading row the maximum.

  28. 28
    When sorting on multiple Pokémon statistics, pandas applies the listed columns as successive sorting
    _____
    .
    Hint

    The first column is considered before the next one.

    Answer

    criteria

    Explanation

    Multiple sort columns provide a primary criterion and additional tie-breaking criteria; each can have its own ascending direction.

  29. 29
    A histogram or box plot can help begin analysis by showing the distribution and potential
    _____
    in numeric data.
    Hint

    These are observations unusually far from the rest of the values.

    Answer

    outliers

    Explanation

    Visualizations such as histograms and box plots provide a quick view of ranges, distributions, and unusual values.

  30. 30
    The birthday paradox asks how many people are needed for the probability that at least two share a birthday to exceed
    _____
    percent.
    Hint

    The surprising threshold occurs with a relatively small group.

    Answer

    50

    Explanation

    The birthday paradox states that only 23 people are needed for the probability of a shared birthday to exceed 50 percent.

  31. 31
    The birthday paradox reaches a probability above 50 percent with only
    _____
    people in a room.
    Hint

    This counterintuitively small number is the central result of the example.

    Answer

    23

    Explanation

    With 23 people, the number of possible pairs makes a shared birthday more likely than many people intuitively expect.

  32. 32
    In a non-leap year, at least
    _____
    people are needed to guarantee that two people share a birthday.
    Hint

    There are 365 possible calendar days in the assumed year.

    Answer

    366

    Explanation

    With 365 days, 366 people guarantee that at least two share a birthday by the pigeonhole principle.

  33. 33
    The birthday probability calculation considers possible pairs using the number of combinations of nnn people taken
    _____
    .
    Hint

    A shared birthday is checked between two people at a time.

    Answer

    two

    Explanation

    The number of candidate pairs is the number of combinations of the group taken two at a time.

  34. 34
    When one more person joins a group, the number of new pairs increases by the number of people already in the
    _____
    .
    Hint

    The newcomer can pair with every person already present.

    Answer

    room

    Explanation

    Each added person forms a new pair with every existing person, so the increase equals the previous group size.

  35. 35
    To compare NBA players' birthdays regardless of birth year, extract the
    _____
    and day from each birth date.
    Hint

    A birthday match ignores the year but retains two calendar components.

    Answer

    month

    Explanation

    The birthday comparison uses month and day only, because people can share a birthday even when born in different years.

  36. 36
    The pandas datetime string formatting operation used to extract month and day from a date column is strftime through the
    _____
    accessor.
    Hint

    This accessor is used for datetime Series operations.

    Answer

    dt

    Explanation

    The dt accessor exposes datetime operations, including strftime formatting, for a pandas datetime Series.

  37. 37
    The itertools function that generates pairs of players without comparing a player with themself is
    _____
    .
    Hint

    It generates unordered selections of a chosen size.

    Answer

    combinations

    Explanation

    combinations creates each distinct pair once, which is suitable for checking which pairs share a birthday.

  38. 38
    For matching company names, the Levenshtein-distance-based library used in the example was
    _____
    .
    Hint

    It provides similarity functions such as partial ratio.

    Answer

    fuzz

    Explanation

    The fuzz library was used to compute similarity scores between company-name strings.

  39. 39
    The fuzz method selected for comparing company names with extra words or partial overlap was
    _____
    .
    Hint

    It compares meaningful parts of strings rather than requiring a full-string match.

    Answer

    partial ratio

    Explanation

    partial ratio was chosen because company names may contain additional words or differ in how their full names are written.

  40. 40
    A similarity score near 100 from the partial ratio method indicates that the compared strings are highly
    _____
    .
    Hint

    It describes closeness between the two company-name strings.

    Answer

    similar

    Explanation

    The score is interpreted as similarity: a high score means the strings have a close match under the method.

  41. 41
    Creating every possible pairing between two company-name lists is a Cartesian product, which can be generated with itertools.
    _____
    .
    Hint

    This function combines each item from one collection with each item from another.

    Answer

    product

    Explanation

    itertools.product generates all cross-list pairs, allowing each name in one dataset to be compared with every name in the other.

  42. 42
    A data-driven company-matching workflow can store both names and their similarity score in a single
    _____
    .
    Hint

    This tabular structure makes filtering and inspection easier.

    Answer

    DataFrame

    Explanation

    Putting candidate pairs and their scores into a DataFrame supports sorting, filtering, plotting, and reviewing possible matches.

  43. 43
    A fixed similarity cutoff can produce false matches, so borderline name comparisons should be checked using
    _____
    knowledge.
    Hint

    This knowledge concerns the business or subject area represented by the data.

    Answer

    domain

    Explanation

    Similarity alone may confuse distinct entities that share words; domain knowledge is needed to decide whether borderline pairs represent the same entity.

  44. 44
    The similarity method in the example can recognize names such as Apple and Apple Inc. by focusing on partial string
    _____
    .
    Hint

    It identifies shared portions despite extra text in one name.

    Answer

    matches

    Explanation

    Partial ratio can score shared parts highly even when one company name includes additional words or abbreviations.

  45. 45
    The first step in investigating a messy dataset is to inspect its structure and data types, for example with the DataFrame method
    _____
    .
    Hint

    It displays column types and non-null counts.

    Answer

    info

    Explanation

    info helps identify suspicious types, missing entries, and the overall structure before cleaning begins.

  46. 46
    For app ratings known to be on a scale from one to five, values greater than five are
    _____
    .
    Hint

    They fall outside the domain's allowed rating range.

    Answer

    invalid

    Explanation

    Understanding the rating scale makes values above five identifiable as invalid; the example replaced such values with missing values.

  47. 47
    The missing-data marker assigned to invalid ratings in the example was
    _____
    .
    Hint

    It is the conventional pandas and NumPy marker for a missing numeric value.

    Answer

    NaN

    Explanation

    Invalid ratings were set to NaN, after which missing ratings could be filled with the mean.

  48. 48
    After invalid ratings were marked missing, the example filled missing rating values using the column's
    _____
    .
    Hint

    It is the arithmetic average of the available rating values.

    Answer

    mean

    Explanation

    The rating column's mean was used to fill missing values in the example.

  49. 49
    When a small number of rows have missing values in other columns, the DataFrame method used to remove those rows is
    _____
    .
    Hint

    Its name refers to dropping missing values.

    Answer

    dropna

    Explanation

    dropna removes rows with missing values; the example used it for a handful of incomplete app records.

  50. 50
    The pandas function that attempts to convert strings such as review counts into numeric values is
    _____
    .
    Hint

    It converts a Series to a numeric type when possible.

    Answer

    to numeric

    Explanation

    to numeric parses numeric strings; using errors set to coerce turns unparseable entries into NaN for investigation.

  51. 51
    In the reviews column, the letter M represented a count in the
    _____
    range and had to be removed and scaled.
    Hint

    A value written as 2M represents two of these units.

    Answer

    millions

    Explanation

    The M suffix indicated millions; the example removed it, converted the remaining text, and multiplied by one million.

  52. 52
    To count repeated app names regardless of differences in other columns, use duplicated with the app column specified through the
    _____
    parameter.
    Hint

    It limits duplicate checking to selected columns.

    Answer

    subset

    Explanation

    Setting subset to app checks whether app names repeat even when other fields, such as review counts, differ.

  53. 53
    To mark every occurrence of a duplicated app name, including its first occurrence, set keep to
    _____
    .
    Hint

    This option does not preserve one occurrence as the unique original.

    Answer

    false

    Explanation

    With keep set to false, duplicated marks every occurrence of a repeated value rather than only later copies.

  54. 54
    After sorting duplicate app records by reviews, keeping the row with the greatest review count requires drop duplicates with keep set to
    _____
    .
    Hint

    In ascending order, the greatest review count appears at the end.

    Answer

    last

    Explanation

    Sorting reviews in ascending order and keeping the last duplicate retains the record with the most reviews.

  55. 55
    To convert category labels from uppercase words joined by underscores into readable labels, replace underscores with spaces and apply
    _____
    .
    Hint

    This string operation gives the label conventional capitalization.

    Answer

    capitalize

    Explanation

    The example replaced underscores with spaces and capitalized the resulting category text.

  56. 56
    When cleaning app sizes, a value in kilobytes is converted to bytes by multiplying by
    _____
    .
    Hint

    This is the conversion factor used for each binary size step in the example.

    Answer

    1024

    Explanation

    Kilobytes were multiplied by 1024 to express sizes in bytes; megabytes required applying that factor twice.

  57. 57
    The Premier League result column had three valid categories: home win, away win, and
    _____
    .
    Hint

    It occurs when the home and away sides score the same number of goals.

    Answer

    draw

    Explanation

    The valid result categories were home victory, away victory, and draw; inconsistent results could be recalculated from the goals.

  58. 58
    In the season column, a question mark did not match the season pattern and was replaced with
    _____
    .
    Hint

    The replacement explicitly indicates that the season could not be identified.

    Answer

    unknown season

    Explanation

    The invalid question-mark entries were replaced by the category unknown season.

  59. 59
    Because a football match cannot have a negative score, negative home and away goal values were replaced with
    _____
    .
    Hint

    This is the minimum possible goal count in a match.

    Answer

    zeros

    Explanation

    Negative goal counts fell outside the valid range and were cleaned by setting them to zero.

  60. 60
    The total goals column for a match is calculated by adding home goals and
    _____
    goals.
    Hint

    It refers to the visiting team's score.

    Answer

    away

    Explanation

    Total goals are the sum of the home team's and away team's goal counts.

  61. 61
    To calculate average goals for each season, group by season and apply the mean to the
    _____
    goals column.
    Hint

    This column combines home and away goals for each match.

    Answer

    total

    Explanation

    Grouping matches by season and averaging total goals gives the average goals per match in each season.

  62. 62
    When the direction of the goal difference does not matter, use the
    _____
    operation to compare its magnitude.
    Hint

    It removes the negative sign while preserving the size of a value.

    Answer

    absolute

    Explanation

    Taking the absolute value treats a win by six goals the same in magnitude whether the home or away team won.

  63. 63
    To identify the team with the most away wins, group by away team and count or sum the rows whose result indicates an away
    _____
    .
    Hint

    It is the result category for a victory by the visiting side.

    Answer

    win

    Explanation

    Grouping by away team and counting away-win results identifies which team won the most matches while playing away.

  64. 64
    In a groupby workflow, the common description of splitting data into groups, applying an operation, and recombining the results is split, apply, and
    _____
    .
    Hint

    It is the final stage when grouped results are assembled again.

    Answer

    combine

    Explanation

    Groupby follows a split-apply-combine pattern: form groups, compute within groups, and combine the results.

  65. 65
    To find the home team that scored the most goals at home, group by home team and calculate the
    _____
    of home goals.
    Hint

    This aggregates all the team's home goals across its matches.

    Answer

    sum

    Explanation

    Summing home goals within each home-team group gives each team's total goals scored at home.

  66. 66
    A left merge of 2017 season statistics with player information retains all rows from the
    _____
    DataFrame.
    Hint

    The left-hand table is the one whose rows are preserved.

    Answer

    left

    Explanation

    A left join preserves every row from the left table and brings in matching information from the right table.

  67. 67
    When merging the NBA season statistics and player information, the player identifier in the season table was matched to the player's
    _____
    field.
    Hint

    The two tables used different column labels for the matching information.

    Answer

    name

    Explanation

    The merge matched the season table's player column with the players table's name column.

  68. 68
    After a merge, missing values in a non-nullable name field can indicate that the player records did not
    _____
    .
    Hint

    The two tables may use different spellings or versions of a name.

    Answer

    match

    Explanation

    If the name field should always exist, a missing merged name indicates that the join did not find a corresponding player record.

  69. 69
    To replace team abbreviations with full team names using a mapping, the Series method used was
    _____
    .
    Hint

    It substitutes matching values according to a mapping.

    Answer

    replace

    Explanation

    The replace method applies the abbreviation-to-full-name mapping to the team column.

  70. 70
    A player appearing for the special TOT team represents an aggregate across teams; those total rows were removed to avoid counting the player
    _____
    .
    Hint

    The player may also appear in separate rows for individual teams.

    Answer

    twice

    Explanation

    The total row aggregates the player's statistics across teams, so retaining it alongside team-specific rows would duplicate the player's contribution.

  71. 71
    To convert a birthday string column to pandas datetime values, use pandas
    _____
    .
    Hint

    It parses date-like strings into datetime objects.

    Answer

    to datetime

    Explanation

    to datetime converts the birthday column from strings to datetime values, enabling date-based operations.

  72. 72
    The groupby transform operation can attach each team's maximum points value back to every player row in that team, preserving the original
    _____
    .
    Hint

    The transformed result aligns with the original rows instead of collapsing to one row per group.

    Answer

    shape

    Explanation

    Unlike an aggregation that reduces each group to one result, transform returns group calculations aligned with the original DataFrame rows.

  73. 73
    When calculating the average player birthday by team, a more recent mean birth date indicates a
    _____
    squad.
    Hint

    Players born later have more recent birthdays and are younger at a fixed reference date.

    Answer

    younger

    Explanation

    For a fixed reference date, a later average birth date corresponds to a lower average age and therefore a younger squad.

1 of 73
Question 1 of 73

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent