1. Home
  2. Explore
  3. Computer Science
  4. Data Science Basics with Python

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Data Science Basics with Python

  • 17Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Python & NumPy Basics

What is the primary advantage of using a NumPy array over a Python list for numerical data?

17 questions

  1. 1

    What is the primary advantage of using a NumPy array over a Python list for numerical data?

    1. A

      NumPy arrays have a fixed size, while lists can grow dynamically.

    2. B

      NumPy arrays can store mixed data types, while lists cannot.

    3. C

      NumPy arrays support element-wise mathematical operations, while lists do not.

    4. D

      NumPy arrays automatically sort data, while lists require manual sorting.

    Correct answer
    C

    NumPy arrays support element-wise mathematical operations, while lists do not.

    Explanation

    NumPy arrays allow element-wise arithmetic (e.g., multiplying each element by 2), whereas multiplying a Python list duplicates the list. This makes NumPy superior for numerical computations.

  2. 2

    In a NumPy array with zero-based indexing, how do you access the third element?

    1. A

      Use index 1

    2. B

      Use index 4

    3. C

      Use index 3

    4. D

      Use index 2

    Correct answer
    D

    Use index 2

    Explanation

    Zero-based indexing means the first element is at index 0, second at 1, third at 2.

  3. 3

    Which method is used to create a pandas DataFrame that resembles a table?

    1. A

      plt.figure()

    2. B

      pd.DataFrame()

    3. C

      np.array()

    4. D

      sns.load_dataset()

    Correct answer
    B

    pd.DataFrame()

    Explanation

    The pd.DataFrame() constructor creates a tabular data structure from dictionaries, lists, or arrays. NumPy arrays and Matplotlib figures are not DataFrames.

  4. 4

    How do you access the entire row with label index 5 in a pandas DataFrame?

    1. A

      df.loc[5]

    2. B

      df.iloc[5]

    3. C

      df.get(5)

    4. D

      df[5]

    Correct answer
    A

    df.loc[5]

    Explanation

    The .loc method accesses rows by label index. .iloc uses integer position. Square brackets alone on a DataFrame select columns, not rows.

  5. 5

    Which method is used to filter rows in a pandas DataFrame where a column equals a specific value?

    1. A

      df[df['column'] == value]

    2. B

      df.filter(column=value)

    3. C

      df.where(column=value)

    4. D

      df.select(column=value)

    Correct answer
    A

    df[df['column'] == value]

    Explanation

    Boolean indexing with df[condition] is the standard way. .filter() works on column names, .select() is not a pandas method, and .where() preserves shape and masks other rows.

  6. 6

    What does the .query() method in pandas require when filtering string columns?

    1. A

      The string value must be preceded by an @ symbol.

    2. B

      The .query() method cannot filter on string columns.

    3. C

      The string value must be passed as a variable without quotes.

    4. D

      The string value must be enclosed in quotes inside the query string.

    Correct answer
    D

    The string value must be enclosed in quotes inside the query string.

    Explanation

    In .query(), string literals must be quoted (e.g., df.query("name == 'Vicky'")). Using @ references Python variables.

  7. 7

    Which of the following is a common method to handle missing values (NaN) in a pandas DataFrame?

    1. A

      Replacing NaN with zero by default

    2. B

      Filling missing values with the mean of the column using fillna()

    3. C

      Automatically ignoring rows with missing values during analysis

    4. D

      Using the .dropna() method to remove all rows with any missing value

    Correct answer
    B

    Filling missing values with the mean of the column using fillna()

    Explanation

    fillna() can fill missing values with a specified value like the mean. dropna() removes rows with missing values, but it is not the only method. The column may have NaN after import, not automatically handled.

  8. 8

    When adding a new column to a pandas DataFrame using pd.concat(), what axis parameter indicates adding a column?

    1. A

      axis=0

    2. B

      axis='row'

    3. C

      axis=1

    4. D

      axis='column'

    Correct answer
    C

    axis=1

    Explanation

    In pandas, axis=0 refers to rows and axis=1 refers to columns. To add a new column (Series) to a DataFrame, you use axis=1.

  9. 9

    What does the following code do? df.groupby('column')['numeric'].mean()

    1. A

      Groups by 'numeric' and computes the mean of 'column' for each group.

    2. B

      Computes the mean of all columns grouped by 'column'.

    3. C

      Groups by 'column' and computes the mean of 'numeric' for each group.

    4. D

      Returns the mean of 'numeric' ignoring groups.

    Correct answer
    C

    Groups by 'column' and computes the mean of 'numeric' for each group.

    Explanation

    The code first groups by 'column', then selects the 'numeric' column and calculates its mean within each group. It does not compute means of all columns.

  10. 10

    In Matplotlib, what does the term 'figure' refer to?

    1. A

      A single plot or chart within the window.

    2. B

      The area inside the axes where data is plotted.

    3. C

      The legend or title of the chart.

    4. D

      The entire window or page that can contain one or more plots.

    Correct answer
    D

    The entire window or page that can contain one or more plots.

    Explanation

    A figure is the top-level container that holds all plot elements, including multiple axes (subplots). An axes is one plot area.

  11. 11

    How do you create a bar chart with student names on the x-axis and grades on the y-axis using Matplotlib?

    1. A

      plt.hist(x=df['name'], bins=df['grade'])

    2. B

      plt.plot(x=df['name'], y=df['grade'])

    3. C

      plt.scatter(x=df['name'], y=df['grade'])

    4. D

      plt.bar(x=df['name'], height=df['grade'])

    Correct answer
    D

    plt.bar(x=df['name'], height=df['grade'])

    Explanation

    plt.bar() expects two arguments: x (categories) and height (values). plt.plot() makes a line plot, plt.scatter() makes a scatter plot, and plt.hist() makes a histogram.

  12. 12

    What does a histogram show about a dataset?

    1. A

      The quartiles and outliers using a box.

    2. B

      The distribution of a continuous variable by binning values and counting frequencies.

    3. C

      The proportion of categories as slices of a circle.

    4. D

      The relationship between two variables with points.

    Correct answer
    B

    The distribution of a continuous variable by binning values and counting frequencies.

    Explanation

    A histogram divides the data range into bins and shows the count of observations in each bin, revealing the distribution shape.

  13. 13

    In a box plot, what does the box represent?

    1. A

      The mode and median of the data.

    2. B

      The entire range from minimum to maximum.

    3. C

      The interquartile range (IQR), containing the middle 50% of the data.

    4. D

      The mean and standard deviation of the data.

    Correct answer
    C

    The interquartile range (IQR), containing the middle 50% of the data.

    Explanation

    The box spans from the first quartile (Q1) to the third quartile (Q3), covering 50% of the data. The whiskers extend to the min and max (excluding outliers).

  14. 14

    What does a standard deviation of 3.4 signify in the context of a normal distribution?

    1. A

      The mean is 3.4 units from zero.

    2. B

      Approximately 68% of the data falls within 3.4 units above or below the mean.

    3. C

      Approximately 95% of the data falls within 3.4 units of the mean.

    4. D

      The data is uniformly distributed around the mean.

    Correct answer
    B

    Approximately 68% of the data falls within 3.4 units above or below the mean.

    Explanation

    For a normal distribution, about 68% of data lies within one standard deviation of the mean. 95% lies within two standard deviations.

  15. 15

    Which of the following best describes the correlation coefficient?

    1. A

      A value between -1 and 1 indicating the strength and direction of a linear relationship.

    2. B

      The p-value from a hypothesis test.

    3. C

      A value that must be positive to indicate a relationship.

    4. D

      The slope of the regression line.

    Correct answer
    A

    A value between -1 and 1 indicating the strength and direction of a linear relationship.

    Explanation

    Correlation coefficients range from -1 (perfect negative) to 1 (perfect positive). Zero means no linear relationship. It is not the slope, and it can be negative.

  16. 16

    In linear regression, what does the slope (m) represent?

    1. A

      The correlation between X and Y.

    2. B

      The proportion of variance explained by the model.

    3. C

      The value of Y when X is zero.

    4. D

      The change in the predicted Y for a one-unit change in X.

    Correct answer
    D

    The change in the predicted Y for a one-unit change in X.

    Explanation

    The slope m indicates how much Y changes on average when X increases by one unit. The intercept b is Y when X=0.

  17. 17

    Using the regression model derived from the data (m=6.31, b=-17.92), what is the predicted grade for a student who studied for 14 hours?

    1. A

      Approximately 98

    2. B

      Approximately 84

    3. C

      Approximately 56

    4. D

      Approximately 70

    Correct answer
    D

    Approximately 70

    Explanation

    Prediction = mX + b = 6.3114 + (-17.92) = 88.34 - 17.92 = 70.42, about 70.

Question 1 of 17
Question 1 of 17

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent