Bird
Raised Fist0
Pandasdata~20 mins

What is Pandas - Practice Questions & Exercises

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pandas Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:00remaining
Understanding the Purpose of Pandas

What is the main purpose of the Pandas library in data science?

ATo build machine learning models
BTo create interactive web pages
CTo manipulate and analyze data easily
DTo design computer graphics
Attempts:
2 left
💡 Hint

Think about what you do with tables of data in Python.

❓ Predict Output
intermediate
1:30remaining
Pandas DataFrame Creation Output

What will be the output of this code?

Pandas
import pandas as pd

df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
print(df)
A
   A  B
0  1  3
1  2  4
BError: DataFrame not defined
C{'A': [1, 2], 'B': [3, 4]}
D[[1, 3], [2, 4]]
Attempts:
2 left
💡 Hint

Look at how DataFrame prints tabular data.

❓ data_output
advanced
1:30remaining
Selecting Data from a DataFrame

Given the DataFrame below, what is the output of df['B'][1]?

Pandas
import pandas as pd

df = pd.DataFrame({'A': [10, 20, 30], 'B': [100, 200, 300]})
A100
BKeyError
C30
D200
Attempts:
2 left
💡 Hint

Remember that df['B'] selects column B, then [1] selects the second row.

❓ visualization
advanced
2:00remaining
Plotting with Pandas

What type of plot will this code produce?

Pandas
import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})
df.plot(x='x', y='y', kind='bar')
plt.show()
AA bar chart showing y values for each x
BA line chart connecting points (x, y)
CA scatter plot of x vs y
DA pie chart of y values
Attempts:
2 left
💡 Hint

The kind='bar' argument controls the plot type.

🔧 Debug
expert
1:30remaining
Error Identification in Pandas Code

What error will this code raise?

Pandas
import pandas as pd

df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
print(df['C'])
ATypeError
BKeyError
CIndexError
DNo error, prints empty column
Attempts:
2 left
💡 Hint

Check if column 'C' exists in the DataFrame.

Practice

(1/5)
1. What is pandas mainly used for in Python?
easy
A. Writing system drivers
B. Creating 3D graphics
C. Building websites
D. Working with tables of data easily

Solution

  1. Step 1: Understand pandas purpose

    Pandas is a Python library designed to handle and analyze data in tables.
  2. Step 2: Match purpose with options

    Only Working with tables of data easily describes working with tables of data, which matches pandas' main use.
  3. Final Answer:

    Working with tables of data easily -> Option D
  4. Quick Check:

    pandas = tables of data [OK]
Hint: Remember pandas = data tables in Python [OK]
Common Mistakes:
  • Confusing pandas with graphics or web tools
  • Thinking pandas is for system programming
2. Which of these is the correct way to import pandas in Python?
easy
A. import pandas as pn
B. import pandas as pd
C. from pandas import table
D. import panda as pd

Solution

  1. Step 1: Recall pandas import convention

    The common and correct way is to import pandas as pd for short.
  2. Step 2: Check each option

    import pandas as pd matches the standard import. Others have wrong names or syntax.
  3. Final Answer:

    import pandas as pd -> Option B
  4. Quick Check:

    Standard import = import pandas as pd [OK]
Hint: Use 'import pandas as pd' always [OK]
Common Mistakes:
  • Misspelling 'pandas' as 'panda'
  • Using wrong alias like 'pn'
  • Trying to import non-existent modules
3. What will this code print?
import pandas as pd
data = {'A': [1, 2], 'B': [3, 4]}
df = pd.DataFrame(data)
print(df)
medium
A. A table with columns A and B showing values 1,2 and 3,4
B. A list of dictionaries
C. An error because DataFrame is not defined
D. Empty output

Solution

  1. Step 1: Create DataFrame from dictionary

    The dictionary has keys 'A' and 'B' with lists as values. pd.DataFrame converts this into a table with columns A and B.
  2. Step 2: Print DataFrame

    Printing df shows a table with two rows: first row 1 and 3, second row 2 and 4 under columns A and B.
  3. Final Answer:

    A table with columns A and B showing values 1,2 and 3,4 -> Option A
  4. Quick Check:

    DataFrame prints table = A table with columns A and B showing values 1,2 and 3,4 [OK]
Hint: DataFrame from dict shows columns and rows [OK]
Common Mistakes:
  • Thinking it prints a list or dictionary
  • Expecting an error without importing pandas
  • Assuming empty output
4. Find the error in this code:
import pandas as pd
data = {'X': [5, 6], 'Y': [7, 8]}
df = pd.Dataframe(data)
print(df)
medium
A. Typo in DataFrame capitalization
B. Missing import statement
C. Dictionary keys must be strings
D. print() function is incorrect

Solution

  1. Step 1: Check pandas DataFrame spelling

    The correct class name is DataFrame with a capital 'F'. The code uses Dataframe which causes an error.
  2. Step 2: Verify other parts

    Import is correct, dictionary keys are strings, and print() is used properly.
  3. Final Answer:

    Typo in DataFrame capitalization -> Option A
  4. Quick Check:

    Class name is DataFrame, not Dataframe [OK]
Hint: Check capitalization of DataFrame class [OK]
Common Mistakes:
  • Writing Dataframe instead of DataFrame
  • Ignoring case sensitivity in Python
  • Assuming print() causes error
5. You have a CSV file with sales data. Which pandas function helps you load this file into a DataFrame for analysis?
hard
A. pd.load_file()
B. pd.open_csv()
C. pd.read_csv()
D. pd.import_csv()

Solution

  1. Step 1: Identify pandas function for CSV files

    Pandas provides read_csv() to load CSV files into DataFrames easily.
  2. Step 2: Check options for correctness

    Only pd.read_csv() is a valid pandas function. Others do not exist.
  3. Final Answer:

    pd.read_csv() -> Option C
  4. Quick Check:

    CSV load = pd.read_csv() [OK]
Hint: Use pd.read_csv() to load CSV files [OK]
Common Mistakes:
  • Using non-existent pandas functions
  • Confusing with file open methods
  • Trying to load CSV without pandas
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard