Programming quiz

NumPy and Pandas Quiz: Code-Based MCQs with Answers

Sharpen your data wrangling skills with 60 code-based questions on NumPy arrays, broadcasting, indexing, pandas DataFrames, loc vs iloc, missing values, groupby, merge and pivot tables. Every output was checked by running the code.

✅ Free · no login60 questions⏱ Timer📝 Explanations🖨 Mark sheet & PDFIntermediate
NumPy & Pandas Quiz: free online quiz with timer and mark sheet by Codanics
Loading…

NumPy & Pandas Quiz

60 questions · 8 topics · timer · instant explanations · printable mark sheet.

  • Questions60 in the bank, 10–30 per attempt
  • Levels20 easy · 24 medium · 16 hard
  • TimeAbout 5–20 minutes
  • PriceFree, no login needed
  • Made byDr. Aammar Tufail, Codanics
  • Updated18 November 2026

In short: the NumPy & Pandas Quiz is a free online multiple-choice quiz by Codanics with 60 questions on arrays, dtypes and shape; broadcasting and vectorisation; indexing, loc and iloc; series, DataFrames, missing data; grouping and pivoting; merge, join and concat; apply, strings and dates; and views, copies and performance. You choose the number of questions and the difficulty, answer against a timer, see an explanation after every answer and finish with a printable mark sheet.

🚀 Follow Codanics for more free quizzes and lessonsNew quizzes, free lessons, scholarships and PhD positions, straight to your phone.

What the NumPy & Pandas Quiz covers

NumPy and pandas are where most data science time is spent. Small details, such as the difference between loc and iloc, how broadcasting works or what groupby returns, decide whether your analysis is right or quietly wrong.

Most questions in this quiz show real code and ask what it returns. The explanations tell you why, so you can fix the habit behind each mistake.

  • Arrays, dtypes and shape 8 questions
  • Broadcasting and vectorisation 8 questions
  • Indexing, loc and iloc 7 questions
  • Series, DataFrames, missing data 8 questions
  • Grouping and pivoting 7 questions
  • Merge, join and concat 8 questions
  • Apply, strings and dates 7 questions
  • Views, copies and performance 7 questions

Who it is for: Data science students who already know basic Python and want to master pandas and NumPy, and job seekers preparing for data analyst or data scientist interviews.

How the quiz works

  1. Type your name if you want it printed on the mark sheet (optional; it never leaves your browser).
  2. Choose 10, 20 or 30 questions, a difficulty (Easy, Mixed or Hard) and the timer: Standard, Relaxed or none.
  3. Answer each question before the timer runs out. Press A–D or 1–4 on a keyboard, or tap an option on your phone.
  4. Read the explanation after every answer, then press Next.
  5. At the end, get your score, grade, topic-wise breakdown and a full answer review. Print it or save it as a PDF.
  6. Retake the quiz for a fresh random set, or practise only the topics you found hard.

Free video lessons from Codanics

Score lower than you hoped? These free lessons from the Codanics YouTube channel cover the same topics, explained step by step.

▶ Full playlist: Python tutorials for data science
Free on the Codanics YouTube channel, taught in Urdu/Hindi.

Sample questions with answers

Here are 8 questions from the bank, with answers and explanations. The quiz above draws from all 60.

1. Which statement about a NumPy ndarray is true?
  1. It can grow in place like a Python list
  2. All its elements share a single dtype
  3. Each element can be a different type
  4. It always has exactly two dimensions

Answer: B. All its elements share a single dtype
An ndarray is a fixed-size block of same-typed values. This uniform layout is what lets NumPy run fast compiled loops over it.

2. What does the following code print? (a = np.arange(3).reshape(3, 1))
import numpy as np
a = np.arange(3).reshape(3, 1)
b = np.arange(4)
print((a + b).shape)
  1. (3, 1)
  2. (3, 4)
  3. (4,)
  4. ValueError

Answer: B. (3, 4)
Broadcasting compares shapes from the right: (3, 1) and (4,) become (3, 1) and (1, 4). Size-1 axes are stretched, giving (3, 4).

3. What does the following code print? (a = np.array([1, 2, 3, 4]))
import numpy as np
a = np.array([1, 2, 3, 4])
print(np.where(a > 2, 1, 0))
  1. [0 0 1 1]
  2. [2 3]
  3. [3 4]
  4. [1 1 0 0]

Answer: A. [0 0 1 1]
np.where(cond, x, y) picks x where the condition is True and y elsewhere, element by element. With only a condition it would return the indices instead.

4. What is the difference between df.loc and df.iloc?
  1. loc selects by label, iloc by integer position
  2. loc selects rows, iloc selects columns
  3. loc is for Series, iloc is for DataFrames
  4. loc is faster, iloc is safer

Answer: A. loc selects by label, iloc by integer position
loc uses index and column labels; iloc uses 0-based positions, like a list. Both can select rows and columns at once.

5. What does the following code print? (a = pd.Series([1, 2], index=["a", "b"]))
import pandas as pd
a = pd.Series([1, 2], index=["a", "b"])
b = pd.Series([10, 20], index=["b", "c"])
print((a + b).to_dict())
  1. {'a': 11, 'b': 22}
  2. {'b': 12}
  3. {'a': nan, 'b': 12.0, 'c': nan}
  4. {'a': 1.0, 'b': 12.0, 'c': 20.0}

Answer: C. {'a': nan, 'b': 12.0, 'c': nan}
pandas aligns on index labels before doing arithmetic. Labels present in only one Series give NaN; use a.add(b, fill_value=0) to treat them as 0.

6. What does the following code print? (a = pd.DataFrame({"id": [1, 2, 3]}))
import pandas as pd
a = pd.DataFrame({"id": [1, 2, 3]})
b = pd.DataFrame({"id": [2, 3, 4]})
print(len(a.merge(b, on="id")), len(a.merge(b, on="id", how="outer")))
  1. 2 4
  2. 3 3
  3. 2 6
  4. 4 2

Answer: A. 2 4
The inner join keeps the shared ids 2 and 3. The outer join keeps all ids from both sides: 1, 2, 3 and 4.

7. What does the following code print? (s = pd.Series([" a ", "b "]))
import pandas as pd
s = pd.Series([" a ", "b  "])
print(s.str.strip().tolist())
  1. [' a ', 'b ']
  2. ['a ', 'b']
  3. ['ab']
  4. ['a', 'b']

Answer: D. ['a', 'b']
str.strip() removes leading and trailing whitespace from every value. This is a common clean-up step for text columns.

8. Which call creates an independent copy of a DataFrame, so changes to it do not affect df?
  1. df.view()
  2. df.copy()
  3. new = df
  4. df.clone()

Answer: B. df.copy()
copy() makes a deep copy by default. new = df only creates a second name for the same object.

Free guides and blogs to study

Free tools for your studies and research

Codanics also has 160+ free online tools for students and researchers: statistics calculators, meta-analysis, PDF and writing tools. They run in your browser, with no login.

Browse all free tools →

Frequently asked questions

Is the NumPy & Pandas Quiz free?

Yes. The NumPy & Pandas Quiz is completely free, with no sign-up, no login and no limit on attempts.

How many questions are in the NumPy & Pandas Quiz?

The question bank has 60 multiple-choice questions (20 easy, 24 medium and 16 hard) across 8 topics. Each attempt draws 10, 20 or 30 of them at random, so every attempt is different.

How does the timer work?

Each question has its own countdown: about 25 seconds for easy, 40 for medium and 55 for hard questions, plus 15 seconds when there is code to read. Choose Relaxed to double the time or switch the timer off to study at your own pace. Unanswered questions count as skipped.

Can I get a certificate or mark sheet?

Yes. When you finish, you get a mark sheet with your name, score, grade, time, topic-wise performance and every answer explained. Use Print or save as PDF to keep it. It is a self-assessment result, not an official certificate.

Are the answers and explanations correct?

Every question was written and reviewed for one clearly correct answer, and code questions were checked by running the code. If you think an answer is wrong, tell us on the Codanics WhatsApp channel or in the YouTube comments and we will fix it.

Do I need to install anything to take the pandas quiz?

No. The quiz runs in your browser. If you want to try the code yourself, open Google Colab or Jupyter and paste the snippet: the output will match the correct answer.

Which pandas and NumPy versions were used?

Recent pandas 2.x and NumPy 2.x releases. Questions avoid deprecated behaviour so the answers stay valid as the libraries evolve.

Is my data stored anywhere?

No. The quiz runs entirely in your browser. Your name, answers and score are not uploaded. Your best score and settings are remembered only in this browser so you can track your progress.

More free quizzes

See all Codanics quizzes → · Courses · Free tools · Blog

Follow Codanics

Created by Dr. Muhammad Aammar Tufail, Codanics. Published 18 November 2026, last updated 18 November 2026. Found a mistake or want a quiz on another topic? Tell us on the WhatsApp channel or contact us.