Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.

Unit 13 MCQs NumPy and Pandas

ECAP792 60 questions. Pick an option to check it.

Read the notes Subjective questions

0 of 60 answered 0 right 0 wrong , 60 left

  1. Question 1 of 60 Introduction to Python Easy

    Which symbol begins a single-line comment in Python?

  2. Question 2 of 60 Introduction to Python Easy

    Which Python function displays output on the screen?

  3. Question 3 of 60 Understanding data types in Python Easy

    What is the Python data type of the value 25?

  4. Question 4 of 60 Understanding data types in Python Easy

    Which Python data type stores either True or False?

  5. Question 5 of 60 Understanding data types in Python Easy

    Which built-in function returns the data type of a Python object?

  6. Question 6 of 60 NumPy Easy

    What is the conventional alias used when importing NumPy?

  7. Question 7 of 60 NumPy Easy

    Which NumPy function creates an array from a Python list?

  8. Question 8 of 60 NumPy Easy

    Which attribute gives the dimensions of a NumPy array?

  9. Question 9 of 60 NumPy Easy

    What does np.zeros(3) create?

  10. Question 10 of 60 Pandas for data analysis Easy

    What is the conventional alias used when importing Pandas?

  11. Question 11 of 60 Pandas for data analysis Easy

    Which Pandas object represents a one-dimensional labeled sequence?

  12. Question 12 of 60 Pandas for data analysis Easy

    Which Pandas object stores data in labeled rows and columns?

  13. Question 13 of 60 Data indexing and selection Easy

    What is the index position of the first element in a Python sequence?

  14. Question 14 of 60 Data indexing and selection Easy

    In Python slicing, what does data[1:4] select?

  15. Question 15 of 60 Data selection in Series Easy

    Which Pandas accessor selects Series values by index label?

  16. Question 16 of 60 Data selection in Series Easy

    Which Pandas accessor selects a Series value by integer position?

  17. Question 17 of 60 Data selection in DataFrame Easy

    If df is a DataFrame, which expression selects the column named age?

  18. Question 18 of 60 Data selection in DataFrame Easy

    Which expression selects the first row of a DataFrame named df by position?

  19. Question 19 of 60 Missing data in Pandas Easy

    Which value commonly represents missing numerical data in Pandas?

  20. Question 20 of 60 Handling missing data Easy

    Which Pandas method replaces missing values with a specified value?

  21. Question 21 of 60 Introduction to Python Medium

    What is the value of result after executing values = [1, 2, 3, 4] and result = [x * 2 if x % 2 == 0 else x for x in values]?

  22. Question 22 of 60 Introduction to Python Medium

    Given a = [1, 2], b = a, and b.append(3), what are the final values of a and b?

  23. Question 23 of 60 NumPy Medium

    If NumPy arrays a and b have shapes (3, 1) and (1, 4), respectively, what is the shape of a + b?

  24. Question 24 of 60 NumPy Medium

    Consider a = np.arange(5), b = a[1:4], and b[0] = 99. What is the resulting value of a?

  25. Question 25 of 60 NumPy Medium

    Given arr = np.array([[1, 4], [3, 2]]), what does arr[arr > 2] return?

  26. Question 26 of 60 NumPy Medium

    For x = np.array([[1, 2, 3], [4, 5, 6]]), what is the result of x.sum(axis=0)?

  27. Question 27 of 60 Understanding data types in Python Medium

    After executing d = {True: "yes", 1: "one"}, what are len(d) and d[True]?

  28. Question 28 of 60 Understanding data types in Python Medium

    What is the typical dtype of np.array([1, 2, np.nan])?

  29. Question 29 of 60 Pandas for data analysis Medium

    Let s1 = pd.Series([1, 2], index=["a", "b"]) and s2 = pd.Series([10, 20], index=["b", "c"]). What does s1 + s2 produce?

  30. Question 30 of 60 Pandas for data analysis Medium

    A DataFrame has team = ["A", "A", "B"] and score = [10, 20, 30]. What does df.groupby("team")["score"].mean() return?

  31. Question 31 of 60 Data selection in Series Medium

    Given s = pd.Series([10, 20, 30], index=["a", "b", "b"]), what does s.loc["b"] return?

  32. Question 32 of 60 Data selection in Series Medium

    Given s = pd.Series([10, 20, 30, 40], index=["a", "b", "c", "d"]), what does s.iloc[1:3] select?

  33. Question 33 of 60 Data selection in DataFrame Medium

    A DataFrame indexed by r1 and r2 has row r2 equal to A=5, B=6, and C=7. What does df.loc["r2", ["A", "C"]] select?

  34. Question 34 of 60 Data selection in DataFrame Medium

    If a DataFrame has columns ordered as A, B, and C, what is the column order in df[["C", "A"]]?

  35. Question 35 of 60 Data indexing and selection Medium

    For df = pd.DataFrame({"A": [1, 3, 2], "B": [10, 20, 30]}), what does df.loc[(df["A"] > 1) & (df["B"] < 30), "B"].tolist() return?

  36. Question 36 of 60 Missing data in Pandas Medium

    What is the result of pd.Series([0, None, np.nan, ""]).isna().tolist()?

  37. Question 37 of 60 Missing data in Pandas Medium

    Rows r1, r2, and r3 contain respectively 2, 1, and 3 non-missing values. Which rows remain after df.dropna(thresh=2)?

  38. Question 38 of 60 Handling missing data Medium

    A DataFrame has team = ["A", "A", "B", "B"] and score = [10, np.nan, np.nan, 30]. What are the scores after df["score"].fillna(df.groupby("team")["score"].transform("median"))?

  39. Question 39 of 60 Handling missing data Medium

    What is the result of pd.Series([1, np.nan, np.nan, 4]).ffill(limit=1).tolist()?

  40. Question 40 of 60 Handling missing data Medium

    What values result from pd.Series([2, np.nan, np.nan, 8]).interpolate(method="linear")?

  41. Question 41 of 60 Introduction to Python Hard

    What does the following code print?

    Python
    def collect(x, bucket=[]):
        bucket.append(x)
        return bucket
    
    a = collect(1)
    b = collect(2)
    a.append(3)
    print(b)

  42. Question 42 of 60 NumPy Hard

    Given the following code, what is the final value of a[0]?

    Python
    import numpy as np
    
    a = np.arange(12).reshape(3, 4)
    b = a[:, [1, 3]]
    c = a[:, 1:3]
    b[0, 0] = 99
    c[0, 0] = 88

  43. Question 43 of 60 Understanding data types in Python Hard

    What does np.result_type(np.int32, np.float32) return under NumPy's standard type-promotion rules?

  44. Question 44 of 60 Understanding data types in Python Hard

    What is produced by the final expression?

    Python
    import numpy as np
    
    a = np.array(['1', '22'], dtype='<U2')
    a[0] = '333'
    a.tolist()

  45. Question 45 of 60 Pandas for data analysis Hard

    What is the result of the final expression?

    Python
    import pandas as pd
    
    s1 = pd.Series({'a': 1, 'b': 2})
    s2 = pd.Series({'b': 10, 'c': 20})
    s1.add(s2, fill_value=0).sort_index().tolist()

  46. Question 46 of 60 Data indexing and selection Hard

    For the following Series, which pair of index lists is returned?

    Python
    import pandas as pd
    
    s = pd.Series(['a', 'b', 'c', 'd'], index=[2, 4, 6, 8])
    list(s.loc[4:8].index), list(s.iloc[1:3].index)

  47. Question 47 of 60 Data selection in Series Hard

    What is the result of the final expression?

    Python
    import pandas as pd
    
    s = pd.Series([10, 20, 30], index=[1, 3, 5])
    (s[1], s.iloc[1])

  48. Question 48 of 60 Data selection in Series Hard

    What is the final value of s.tolist()?

    Python
    import pandas as pd
    
    s = pd.Series([1, 2, 3], index=['a', 'a', 'b'])
    s.loc['a'] = 0

  49. Question 49 of 60 Data selection in DataFrame Hard

    What does the final expression return?

    Python
    import pandas as pd
    
    df = pd.DataFrame({'x': [1, 2, 3]}, index=['a', 'b', 'c'])
    mask = pd.Series([True, False, True], index=['c', 'a', 'b'])
    df.loc[mask, 'x'].tolist()

  50. Question 50 of 60 Data selection in DataFrame Hard

    What is returned by the final expression?

    Python
    import pandas as pd
    
    idx = pd.MultiIndex.from_product([['A', 'B'], [1, 2]])
    df = pd.DataFrame({'v': [0, 1, 2, 3]}, index=idx)
    df.loc[('A', slice(None)), 'v'].tolist()

  51. Question 51 of 60 Data selection in DataFrame Hard

    Given duplicate column labels, what does the final expression produce?

    Python
    import pandas as pd
    
    df = pd.DataFrame([[1, 2, 3]], columns=['x', 'x', 'y'])
    (type(df['x']).__name__, df['x'].shape)

  52. Question 52 of 60 Missing data in Pandas Hard

    Under Pandas' nullable Boolean logic, what is the result?

    Python
    import pandas as pd
    
    s = pd.Series([True, pd.NA, False], dtype='boolean')
    (s & False).tolist()

  53. Question 53 of 60 Missing data in Pandas Hard

    What does the final expression return under the default Pandas missing-value rules?

    Python
    import numpy as np
    import pandas as pd
    
    s = pd.Series([np.nan, None, pd.NA, np.inf], dtype='object')
    pd.isna(s).tolist()

  54. Question 54 of 60 Handling missing data Hard

    Which index remains after the final operation?

    Python
    import numpy as np
    import pandas as pd
    
    df = pd.DataFrame({
        'a': [1, np.nan, 3],
        'b': [np.nan, 2, 4],
        'c': [np.nan, 3, np.nan]
    }, index=['r0', 'r1', 'r2'])
    
    df.dropna(subset=['a', 'b'], thresh=2).index.tolist()

  55. Question 55 of 60 Pandas for data analysis Hard

    Which description matches the result?

    Python
    import numpy as np
    import pandas as pd
    
    df = pd.DataFrame({
        'k': ['a', 'a', None, 'b'],
        'v': [1.0, np.nan, 3.0, np.nan]
    })
    r = df.groupby('k')['v'].sum(min_count=1)

  56. Question 56 of 60 Handling missing data Hard

    What is the result of s.ffill(limit=1).tolist()?

    Python
    import numpy as np
    import pandas as pd
    
    s = pd.Series([1.0, np.nan, np.nan, 4.0, np.nan])

  57. Question 57 of 60 Handling missing data Hard

    What does the interpolation produce?

    Python
    import numpy as np
    import pandas as pd
    
    s = pd.Series([np.nan, 1.0, np.nan, np.nan, 4.0, np.nan])
    s.interpolate(limit_area='inside').tolist()

  58. Question 58 of 60 NumPy Hard

    Let a.shape == (2, 3) and b.shape == (2,). Which expression adds b[i] to every element of row i without explicitly constructing a full (2, 3) array?

  59. Question 59 of 60 NumPy Hard

    What is the result of the final expression?

    Python
    import numpy as np
    
    a = np.arange(6).reshape(2, 3)
    b = a.T.reshape(6)
    b[0] = -1
    (np.shares_memory(a, b), a[0, 0])

  60. Question 60 of 60 Data indexing and selection Hard

    What is df['x'].tolist() after the aligned assignment?

    Python
    import numpy as np
    import pandas as pd
    
    df = pd.DataFrame({'x': [0.0, 0.0, 0.0]}, index=['a', 'b', 'c'])
    rhs = pd.Series([10.0, 20.0], index=['c', 'a'])
    df.loc[:, 'x'] = rhs

That's unit 13

Answer a few questions and your score shows up here.