NumPy and Pandas Functions Quiz
8 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What does np.arange(7) return?

  • [0, 1, 2, 3, 4, 5, 6] (correct)
  • [1, 2, 3, 4, 5, 6, 7]
  • [1, 2, 3, 4, 5, 6]
  • [0, 2, 4, 6]
  • Given arr = np.array([[1, 2, 3], [4, 5, 6]]), what will arr.sum(axis=0) output?

  • [1, 2, 3]
  • [3, 6]
  • [6, 15]
  • [5, 7, 9] (correct)
  • Which NumPy function will generate a 4x4 matrix with all elements as zeros?

  • np.ones((4, 4))
  • np.zeros((4, 4)) (correct)
  • np.identity(4)
  • np.diag([0, 0, 0, 0])
  • What does np.random.randint(1, 10, 3) do?

    <p>Generates 3 random integers between 1 and 9 (A)</p> Signup and view all the answers

    Given a = np.array([1, 2, 3]) and b = np.array([2, 2, 2]), what will np.dot(a, b) output?

    <p>12 (B)</p> Signup and view all the answers

    Which method, given an array arr, can be used to insert a new column at a specific index?

    <p><code>np.insert(arr, index, values, axis=1)</code> (B)</p> Signup and view all the answers

    Given df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}), what does df['B'].sum() return?

    <p>15 (D)</p> Signup and view all the answers

    Given a DataFrame df, how can you select all rows where column 'A' is greater than 2 and column 'B' is less than 5?

    <p><code>df[(df['A'] &gt; 2) &amp; (df['B'] &lt; 5)]</code> (D)</p> Signup and view all the answers

    Study Notes

    NumPy Functions

    • np.arange(5) returns [0, 1, 2, 3, 4]
    • sum(axis=1) calculates the row-wise sums in a 2D array

    NumPy Identity Matrix

    • np.identity(3) generates a 3x3 identity matrix

    Random Number Generation

    • np.random.random() generates random numbers between 0 and 1

    NumPy Array Operations

    • np.append() adds a new row to the end of a NumPy array

    Pandas DataFrame Operations

    • The sum() method on a Pandas Series calculates the sum of the values.

    • df.isnull() checks for missing or NaN values in a DataFrame.

    • df.groupby() groups data based on column values, enabling aggregation and transformation

    • df.dropna() removes rows containing missing values.

    • To select rows where 'A' is greater than 2, use df.loc[df['A'] > 2], df.query('A > 2'), or df[df['A'] > 2]

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Test your knowledge of NumPy and Pandas functions with this quiz. It covers various aspects like array manipulations, identity matrices, random number generation, and DataFrame operations, including sums, grouping, and missing values. Perfect for students learning data manipulation in Python!

    More Like This

    Numpy Mastery Quiz
    5 questions

    Numpy Mastery Quiz

    UnequivocalGreenTourmaline avatar
    UnequivocalGreenTourmaline
    Week 2: Introduction to NumPy
    37 questions
    NumPy Arrays and Linear Algebra
    27 questions
    Use Quizgecko on...
    Browser
    Browser