Bird
Raised Fist0
Data Analysis Pythondata~10 mins

Essential libraries overview (Pandas, NumPy, Matplotlib) in Data Analysis Python - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Pandas library with the common alias.

Data Analysis Python
import [1] as pd
Drag options to blanks, or click blank then click option'
Anumpy
Bmatplotlib
Cpandas
Dseaborn
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'numpy' instead of 'pandas'.
Using 'matplotlib' which is for plotting.
Using 'seaborn' which is another plotting library.
2fill in blank
medium

Complete the code to create a NumPy array from a Python list.

Data Analysis Python
import numpy as np
arr = np.[1]([1, 2, 3, 4])
Drag options to blanks, or click blank then click option'
Aarray
Bseries
Cmatrix
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list' which is a Python type, not a NumPy function.
Using 'matrix' which is a different NumPy type.
Using 'series' which is from Pandas.
3fill in blank
hard

Fix the error in the code to plot a simple line graph using Matplotlib.

Data Analysis Python
import matplotlib.pyplot as plt
plt.[1]([1, 2, 3], [4, 5, 6])
plt.show()
Drag options to blanks, or click blank then click option'
Ascatter
Bplot
Chist
Dbar
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'scatter' which draws points, not lines.
Using 'hist' which draws histograms.
Using 'bar' which draws bar charts.
4fill in blank
hard

Fill both blanks to create a Pandas DataFrame from a dictionary and show its first rows.

Data Analysis Python
import pandas as pd
data = {'name': ['Anna', 'Bob'], 'age': [25, 30]}
df = pd.[1](data)
print(df.[2]())
Drag options to blanks, or click blank then click option'
ADataFrame
BSeries
Chead
Dtail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Series' instead of 'DataFrame' to create the table.
Using 'tail()' instead of 'head()' to show rows.
5fill in blank
hard

Fill all three blanks to create a NumPy array, calculate its mean, and print the result.

Data Analysis Python
import numpy as np
arr = np.[1]([10, 20, 30, 40])
mean_value = arr.[2]()
print([3])
Drag options to blanks, or click blank then click option'
Aarray
Bmean
Cmean_value
Dmedian
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'median' instead of 'mean' to calculate average.
Printing 'arr' instead of the mean value.
Using 'Series' instead of 'array' to create the array.

Practice

(1/5)
1. Which library is mainly used to organize data in tables for easy analysis?
easy
A. Seaborn
B. NumPy
C. Matplotlib
D. Pandas

Solution

  1. Step 1: Understand library purposes

    Pandas is designed to organize data in tables called DataFrames.
  2. Step 2: Match library to task

    Since the question asks about organizing data in tables, Pandas fits best.
  3. Final Answer:

    Pandas -> Option D
  4. Quick Check:

    Tables = Pandas [OK]
Hint: Tables mean Pandas, numbers mean NumPy, charts mean Matplotlib [OK]
Common Mistakes:
  • Confusing NumPy with Pandas for table data
  • Thinking Matplotlib organizes data
  • Choosing Seaborn which is for visualization, not tables
2. Which of the following is the correct way to import NumPy in Python?
easy
A. import matplotlib.pyplot as plt
B. import pandas as pd
C. import numpy as np
D. import numpy as pd

Solution

  1. Step 1: Recall standard import conventions

    NumPy is commonly imported as 'np' to shorten code.
  2. Step 2: Check each option

    import numpy as np uses 'import numpy as np' which is correct; others are for different libraries or wrong aliases.
  3. Final Answer:

    import numpy as np -> Option C
  4. Quick Check:

    NumPy alias = np [OK]
Hint: NumPy is always imported as np [OK]
Common Mistakes:
  • Using wrong alias like pd for NumPy
  • Mixing import statements of different libraries
  • Forgetting 'as' keyword
3. What will be the output of this code?
import numpy as np
arr = np.array([1, 2, 3])
print(arr * 2)
medium
A. [2 4 6]
B. [1 2 3 1 2 3]
C. [3 4 5]
D. Error

Solution

  1. Step 1: Understand NumPy array multiplication

    Multiplying a NumPy array by a number multiplies each element by that number.
  2. Step 2: Calculate element-wise multiplication

    Each element in [1, 2, 3] multiplied by 2 gives [2, 4, 6].
  3. Final Answer:

    [2 4 6] -> Option A
  4. Quick Check:

    Array * 2 doubles each element [OK]
Hint: NumPy * number multiplies each element [OK]
Common Mistakes:
  • Thinking * duplicates the array
  • Expecting element-wise addition instead of multiplication
  • Assuming syntax error
4. Find the error in this code snippet:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5])
plt.show()
medium
A. plt.show() is missing
B. The lists have different lengths causing an error
C. Wrong import statement for matplotlib
D. No error, code runs fine

Solution

  1. Step 1: Check input lists length

    Plotting requires x and y lists to have the same length.
  2. Step 2: Identify mismatch

    Here, x has 3 elements, y has 2, causing a ValueError.
  3. Final Answer:

    The lists have different lengths causing an error -> Option B
  4. Quick Check:

    Plot lists length must match [OK]
Hint: x and y lists must be same length for plot [OK]
Common Mistakes:
  • Ignoring length mismatch
  • Thinking plt.show() is missing
  • Assuming import is wrong
5. You have a Pandas DataFrame with a column 'Age'. Which library and method would you use to quickly calculate the average age?
hard
A. Pandas' mean() method on the 'Age' column
B. Matplotlib's plot() on the 'Age' column
C. NumPy's np.mean() on the 'Age' column
D. NumPy's array() to convert 'Age' column

Solution

  1. Step 1: Identify the data structure

    The 'Age' column is part of a Pandas DataFrame.
  2. Step 2: Choose the best method for average

    Pandas columns have a built-in mean() method to calculate average quickly.
  3. Step 3: Compare options

    NumPy's np.mean() works but requires extra step; Matplotlib is for plotting, not calculation.
  4. Final Answer:

    Pandas' mean() method on the 'Age' column -> Option A
  5. Quick Check:

    DataFrame column average = mean() [OK]
Hint: Use Pandas mean() directly on DataFrame columns [OK]
Common Mistakes:
  • Using Matplotlib for calculations
  • Converting column unnecessarily with NumPy
  • Not using built-in Pandas methods
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