get started with python coursera week 4 quiz answers

Test your knowledge: Lists and tuples

1. Lists and their contents are immutable, so their elements cannot be modified, added, or removed.

  • True
  • False

2. What Python method adds an element to the end of a list?

  • append()
  • type()
  • pop()
  • remove()

3. A data professional wants to instantiate a tuple. What Python elements can they use to do so? Select all that apply.

  • The tuple() function
  • Parentheses
  • The insert() function
  • Square brackets

4. What Python technique formulaically creates a new list based on the values in an existing list?

  • List comprehension
  • List conversion
  • List sequencing
  • List nesting

Test your knowledge: Dictionaries and sets

5. Fill in the blank: In Python, a dictionary’s _____ must be immutable.

  • sets
  • lists
  • keys
  • order

6. In Python, what does the items() method retrieve?

  • Both a dictionary’s keys and values
  • Only a dictionary’s keys
  • A dictionary’s sets
  • Only a dictionary’s values

7. A data professional is working with two Python sets. What function can they use to find all the elements from both sets?

  • intersection()
  • difference()
  • symmetric_difference()
  • union()

Test your knowledge: Arrays and vectors with NumPy

8. Python libraries and packages include which of the following features? Select all that apply.

  • Documentation
  • Reusable collections of code
  • Cells
  • Modules

9. What is the core data structure of NumPy?

  • Dictionary
  • Global variable
  • Array
  • List

10. A data professional wants to confirm the number of dimensions of an array. What NumPy attribute can they use to do so?

  • shape
  • ndim
  • dimension
  • dtype

Test your knowledge: Dataframes with pandas

11. Fill in the blank: In pandas, a _____ is a one-dimensional, labeled array.

  • dataframe
  • series
  • CSV file
  • key

12. In pandas, what is Boolean masking used for?

  • Merging data in a dataframe
  • Adding data to a dataframe
  • Filtering data in a dataframe
  • Deleting data from a dataframe

13. What is a pandas method that groups rows of a dataframe together based on their values at one or more columns?

  • groupby()
  • keys()
  • values()
  • agg()

14. A data professional wants to join two dataframes together. The dataframes contain identically formatted data that needs to be combined vertically. What pandas function can the data professional use to join the dataframes?

  • concat()
  • type()
  • insert()
  • merge()

Weekly challenge 4

15. Fill in the blank: In Python, _____ indicate where a list starts and ends.

  • square brackets
  • braces
  • quotation marks
  • parentheses

16. A data professional is working with a list named cities that contains data on global cities. What Python code can they use to add the string 'Tokyo' to the end of the list?

  • cities.append(‘Tokyo’)
  • cities.import(‘Tokyo’)
  • cities.pop(‘Tokyo’)
  • cities.insert(‘Tokyo’)

17. In Python, which of the following characters can a data professional use to instantiate a tuple?

  • { }
  • < >
  • ( ) 
  • [ ]

18. Which of the following statements accurately describe Python dictionaries? Select all that apply.

  • Dictionaries are instantiated with quotation marks.
  • Dictionaries consist of collections of key-value pairs.
  • Dictionaries are unordered.
  • Dictionaries are ordered.

19. A data professional is working with a dictionary named employees that contains employee data for a healthcare company. What Python code can they use to retrieve both the dictionary’s keys and values?

  • employees.keys()
  • items.employees()
  • employees.items()
  • keys.employees()

20. A data professional is working with two Python sets. What function can they use to find the elements that the two sets have in common?

  • union()
  • intersection()
  • difference()
  • symmetric_difference()

21. Where are modules accessed in Python?

  • Within a set
  • Within a global variable
  • Within a package or library
  • Within a dictionary

22. Fill in the blank: A _____ NumPy array can be created from a list of lists, where each internal list is the same length.

  • four-dimensional
  • one-dimensional
  • three-dimensional
  • two-dimensional

23. A data professional is working with a pandas dataframe named sales that contains sales data for a retail website. They want to know the price of the least expensive item. What code can they use to calculate the minimum value of the Price column?

  • sales[‘Price’].min()
  • sales.min().(Price)
  • sales = ‘Price’.min()
  • sales.min().Price

24. In pandas, what is the difference between the iloc[] and loc[] methods?

  • iloc[] merges two dataframes vertically; loc[] merges two dataframes horizontally.
  • iloc[] selects dataframe rows and columns by name; loc[] selects dataframe rows and columns by index.
  • iloc[] merges two dataframes horizontally; loc[] merges two dataframes vertically.
  • iloc[] selects dataframe rows and columns by index; loc[] selects dataframe rows and columns by name.

25. A data professional wants to merge two pandas dataframes. They want to join the data so only the keys that are in both dataframes get included in the merge. What technique can they use to do so?

  • Inner join
  • Outer join
  • Right join
  • Left join

26. In Python, what data structure helps store and manipulate an ordered collection of items?

  • Tuple
  • Dictionary
  • Set
  • List

27. A data professional is working with a list named cities that contains data on global cities. The string 'Houston' is the third element in the list. What Python code can they use to remove the string 'Houston' from the list?

  • cities.pop(2)
  • cities.pop(4)
  • cities.pop(3)
  • cities.pop(1)

28. A data professional is working with a dictionary named employees that contains employee data for a healthcare company. What Python code can they use to retrieve only the dictionary’s values?

  • values.employees()
  • items.employees()
  • employees.items()
  • employees.values()

29. A data professional is working with two Python sets. What function can they use to find elements from both sets that are mutually not present in the other?

  • union()
  • difference()
  • intersection()
  • symmetric_difference()

30. Fill in the blank: In Python, _____ typically contain a collection of functions and global variables.

  • modules
  • logical operators
  • keywords
  • comparators

31. A data professional is working with a pandas dataframe named sales that contains sales data for a retail website. They want to know the average price of an item. What code can they use to calculate the mean value of the Price column?

  • sales.mean().[Price]
  • sales = mean().Price
  • sales.(Price).mean()
  • sales[‘Price’].mean()

32. A data professional is working with a pandas dataframe. They want to select a subset of rows and columns by index. What method can they use to do so?

  • concat()
  • loc[]
  • iloc[]
  • merge()

33. Which of the following statements accurately describe Python tuples? Select all that apply.

  • Tuples can be split into separate variables.
  • Tuples are sequences.
  • Tuples are immutable.
  • Tuples cannot be split into separate variables.

34. A data professional is working with two Python sets. What function can they use to find the elements present in one set, but not the other?

  • intersection()
  • difference()
  • union()
  • Left

35. A data professional wants to merge two pandas dataframes. They want to join the data so all of the keys in the left dataframe are included—even if they are not in the right dataframe. What technique can they use to do so?

  • Outer join
  • Inner join
  • Right join
  • Left join

36. Which of the following statements accurately describe Python lists? Select all that apply.

  • Lists can be indexed and sliced.
  • Lists are immutable.
  • Lists are mutable.
  • Lists can contain sequences of elements of any data type.

37. A data professional is working with a NumPy array that has three rows and two columns. They want to change the data into two rows and three columns. What method can they use to do so?

  • agg()
  • type()
  • groupby()
  • reshape()

Leave a Reply