PYTHON Data Science Numpy Pandas MCQs

  1. Which library provides support for arrays in Python Data Science?
    a) NumPy
    b) Pandas
    c) Matplotlib
    d) SciPy
    View Answer

    Correct answer: A — NumPy

  2. What will be printed?
    1 python
    2 import numpy as np
    3 a = np.array([1,2,3])
    4 print(a.shape)
    a) (3,)
    b) (1,3)
    c) Error
    d) None
    View Answer

    Correct answer: A — (3,)

  3. Which function creates an array of zeros in NumPy?
    a) np.zeros()
    b) np.empty()
    c) np.ones()
    d) None
    View Answer

    Correct answer: A — np.zeros()

  4. What is the output of print(np.zeros((2,2)))?
    a) [[0. 0.] [0. 0.]]
    b) [0,0]
    c) Error
    d) None
    View Answer

    Correct answer: A — [[0. 0.] [0. 0.]]

  5. Which function creates an identity matrix?
    a) np.eye()
    b) np.identity()
    c) np.ones()
    d) None
    View Answer

    Correct answer: A — np.eye()

  6. What will be printed?
    1 python
    2 import numpy as np
    3 print(np.eye(3))
    a) 3x3 identity matrix
    b) Error
    c) None
    d) 3x3 zeros
    View Answer

    Correct answer: A — 3x3 identity matrix

  7. Which function creates evenly spaced values?
    a) np.linspace()
    b) np.arange()
    c) np.range()
    d) None
    View Answer

    Correct answer: A — np.linspace()

  8. What is the output of print(np.linspace(1,5,5))?
    a) [1. 2. 3. 4. 5.]
    b) [1,5]
    c) Error
    d) None
    View Answer

    Correct answer: A — [1. 2. 3. 4. 5.]

  9. Which function reshapes an array?
    a) reshape()
    b) resize()
    c) shape()
    d) None
    View Answer

    Correct answer: A — reshape()

  10. What will be printed?
    1 python
    2 import numpy as np
    3 a = np.array([1,2,3,4])
    4 print(a.reshape(2,2))
    a) [[1 2] [3 4]]
    b) [1,2,3,4]
    c) Error
    d) None
    View Answer

    Correct answer: A — [[1 2] [3 4]]

  11. Which function performs matrix multiplication?
    a) np.dot()
    b) np.multiply()
    c) np.matmul()
    d) Both A and C
    View Answer

    Correct answer: D — Both A and C

  12. What is the output of below code?
    1 python
    2 import numpy as np
    3 a = np.array([[1,2],[3,4]])
    4 b = np.array([[5,6],[7,8]])
    5 print(np.dot(a,b))
    a) [[19 22] [43 50]]
    b) [[5 6] [7 8]]
    c) Error
    d) None
    View Answer

    Correct answer: A — [[19 22] [43 50]]

  13. Which function computes mean in NumPy?
    a) np.mean()
    b) np.average()
    c) np.median()
    d) None
    View Answer

    Correct answer: A — np.mean()

  14. What will be printed?
    1 python
    2 import numpy as np
    3 print(np.mean([1,2,3]))
    a) 2.0
    b) 6
    c) Error
    d) None
    View Answer

    Correct answer: A — 2.0

  15. Which library provides Series and DataFrame?
    a) Pandas
    b) NumPy
    c) Matplotlib
    d) SciPy
    View Answer

    Correct answer: A — Pandas

  16. What is the output of below code?
    1 python
    2 import pandas as pd
    3 s = pd.Series([1,2,3])
    4 print(type(s))
    a) <class 'pandas.core.series.Series'>
    b) list
    c) Error
    d) None
    View Answer

    Correct answer: A — <class 'pandas.core.series.Series'>

  17. Which function creates a DataFrame?
    a) pd.DataFrame()
    b) pd.Series()
    c) pd.Frame()
    d) None
    View Answer

    Correct answer: A — pd.DataFrame()

  18. What will be printed?
    1 python
    2 import pandas as pd
    3 df = pd.DataFrame({"Eduinq":[1,2,3]})
    4 print(df.shape)
    a) (3,1)
    b) (1,3)
    c) Error
    d) None
    View Answer

    Correct answer: A — (3,1)

  19. Which function reads CSV file in Pandas?
    a) pd.read_csv()
    b) pd.read()
    c) pd.csv()
    d) None
    View Answer

    Correct answer: A — pd.read_csv()

  20. What is the output of below code?
    1 python
    2 import pandas as pd
    3 print(hasattr(pd,"read_csv"))
    a) True
    b) False
    c) Error
    d) None
    View Answer

    Correct answer: A — True

  21. Which function shows first rows of DataFrame?
    a) head()
    b) tail()
    c) sample()
    d) None
    View Answer

    Correct answer: A — head()

  22. What will be printed?
    1 python
    2 import pandas as pd
    3 df = pd.DataFrame({"Eduinq":[1,2,3]})
    4 print(df.head(2))
    a) First 2 rows
    b) Last 2 rows
    c) Error
    d) None
    View Answer

    Correct answer: A — First 2 rows

  23. Which function shows last rows of DataFrame?
    a) tail()
    b) head()
    c) sample()
    d) None
    View Answer

    Correct answer: A — tail()

  24. What is the output of df.tail(1)?
    a) Last row
    b) First row
    c) Error
    d) None
    View Answer

    Correct answer: A — Last row

  25. Which function describes statistics of DataFrame?
    a) describe()
    b) info()
    c) summary()
    d) None
    View Answer

    Correct answer: A — describe()

  26. What will be printed?
    1 python
    2 import pandas as pd
    3 df = pd.DataFrame({"Eduinq":[1,2,3]})
    4 print("mean" in df.describe().index)
    a) False
    b) True
    c) Error
    d) None
    View Answer

    Correct answer: A — False

  27. Which function shows DataFrame info?
    a) info()
    b) describe()
    c) summary()
    d) None
    View Answer

    Correct answer: A — info()

  28. What is the output of df.info()?
    a) Column info
    b) Data values
    c) Error
    d) None
    View Answer

    Correct answer: A — Column info

  29. Which function selects rows by condition?
    a) loc[]
    b) iloc[]
    c) at[]
    d) None
    View Answer

    Correct answer: A — loc[]

  30. What will be printed?
    1 python
    2 import pandas as pd
    3 df = pd.DataFrame({"Eduinq":[1,2,3]})
    4 print(df.loc[df["Eduinq"]>2])
    a) Row with 3
    b) Row with 1
    c) Error
    d) None
    View Answer

    Correct answer: A — Row with 3

  31. Which function selects rows by index position?
    a) iloc[]
    b) loc[]
    c) at[]
    d) None
    View Answer

    Correct answer: A — iloc[]

  32. What is the output of df.iloc[0]?
    a) First row
    b) Last row
    c) Error
    d) None
    View Answer

    Correct answer: A — First row

  33. Which function merges DataFrames?
    a) merge()
    b) concat()
    c) join()
    d) None
    View Answer

    Correct answer: A — merge()

  34. What will be printed?
    1 python
    2 import pandas as pd
    3 df1 = pd.DataFrame({"id":[1],"val":["E"]})
    4 df2 = pd.DataFrame({"id":[1],"val":["duinq"]})
    5 print(pd.merge(df1,df2,on="id"))
    a) Merged DataFrame
    b) Error
    c) None
    d) id only
    View Answer

    Correct answer: A — Merged DataFrame

  35. Which function concatenates DataFrames?
    a) concat()
    b) merge()
    c) join()
    d) None
    View Answer

    Correct answer: A — concat()

  36. What is the output of pd.concat([df1,df2])?
    a) Combined rows
    b) Error
    c) None
    d) id only
    View Answer

    Correct answer: A — Combined rows

  37. Which function joins DataFrames?
    a) join()
    b) merge()
    c) concat()
    d) None
    View Answer

    Correct answer: A — join()

  38. What will be printed?
    1 python
    2 import pandas as pd
    3 df1 = pd.DataFrame({"Eduinq":[1]},index=["A"])
    4 df2 = pd.DataFrame({"Eduinq":[2]},index=["B"])
    5 print(df1.join(df2,lsuffix="_1",rsuffix="_2"))
    a) Joined DataFrame
    b) Error
    c) None
    d) Eduinq only
    View Answer

    Correct answer: A — Joined DataFrame

  39. Which function groups data in Pandas?
    a) groupby()
    b) aggregate()
    c) pivot()
    d) None
    View Answer

    Correct answer: A — groupby()

  40. What is the output of df.groupby("Eduinq").size()?
    a) Group counts
    b) Error
    c) None
    d) Eduinq
    View Answer

    Correct answer: A — Group counts

  41. Which function creates pivot table?
    a) pivot_table()
    b) pivot()
    c) table()
    d) None
    View Answer

    Correct answer: A — pivot_table()

  42. What will be printed?
    1 python
    2 import pandas as pd
    3 df = pd.DataFrame({"A":[1,2,1],"B":[3,4,5]})
    4 print(df.pivot_table(values="B",index="A",aggfunc="mean"))
    a) Mean grouped by A
    b) Error
    c) None
    d) B only
    View Answer

    Correct answer: A — Mean grouped by A

  43. Which function fills missing values?
    a) fillna()
    b) dropna()
    c) replace()
    d) None
    View Answer

    Correct answer: A — fillna()

  44. What is the output of df.fillna(0)?
    a) Missing replaced with 0
    b) Error
    c) None
    d) Drop missing
    View Answer

    Correct answer: A — Missing replaced with 0

  45. Which function drops missing values?
    a) dropna()
    b) fillna()
    c) replace()
    d) None
    View Answer

    Correct answer: A — dropna()

  46. What will be printed?
    1 python
    2 import pandas as pd
    3 df = pd.DataFrame({"Eduinq":[1,None,3]})
    4 print(df.dropna())
    a) Rows without None
    b) Error
    c) None
    d) Eduinq only
    View Answer

    Correct answer: A — Rows without None

  47. Which function replaces values?
    a) replace()
    b) fillna()
    c) dropna()
    d) None
    View Answer

    Correct answer: A — replace()

  48. What is the output of df.replace(1,"E")?
    a) 1 replaced with E
    b) Error
    c) None
    d) Eduinq only
    View Answer

    Correct answer: A — 1 replaced with E

  49. Which function converts DataFrame to NumPy array?
    a) to_numpy()
    b) as_matrix()
    c) values()
    d) None
    View Answer

    Correct answer: A — to_numpy()

  50. What will be printed?
    1 python
    2 import pandas as pd
    3 df = pd.DataFrame({"Eduinq":[1,2,3]})
    4 print(df.to_numpy())
    a) [[1],[2],[3]]
    b) [1,2,3]
    c) Error
    d) None
    View Answer

    Correct answer: A — [[1],[2],[3]]

Quick Links to Explore