Data Science Practice Questions & Answers

Practise Data Science with 250 questions and 1 full-length mock exams on Exam Clue. Free sample questions with answers below.

250 questions1 mock exams

Sample Data Science Questions

Free sample questions with the correct answer highlighted.

  1. Q1. You load a 5 GB CSV file on a machine with 8 GB RAM using Pandas. Memory usage spikes and the kernel crashes. What is the most memory-efficient way to process this file in Pandas?

    • A. Convert the CSV file to an array using np.loadtxt() first
    • B. Load data with pd.read_excel() instead of pd.read_csv()
    • C. Use df.dropna() before loading the file into memory
    • D. Use pd.read_csv() with chunksize parameter to iterate over data blocks
  2. Q2. In a dataset containing customer records, the salary column has missing values primarily for entry-level roles where experience_years is 0. What mechanism of missingness is present, and how should you impute it?

    • A. Structural missingness; replace all missing values with global mean
    • B. Missing Not at Random (MNAR); fill all missing values with 0 using .fillna(0)
    • C. Missing at Random (MAR); group by experience_years and impute using median
    • D. Missing Completely at Random (MCAR); drop all missing rows using .dropna()
  3. Q3. You have a high-cardinality string column 'user_status' containing values 'Active', 'Pending', and 'Inactive' across 10 million rows in Pandas. How can you significantly cut RAM usage?

    • A. Convert column to string type via df['user_status'].astype('string')
    • B. Convert column to integer using pd.to_numeric()
    • C. Apply string strip via df['user_status'].apply(lambda x: x.strip())
    • D. Convert column to categorical type via df['user_status'].astype('category')
  4. Q4. You need to perform a join between two DataFrames: sales and returns. You want to keep every sale record regardless of whether it was returned, but duplicate sale rows if multiple returns exist. Which code achieves this?

    • A. pd.concat([sales, returns], axis=1, join='inner')
    • B. sales.join(returns, lsuffix='_sales', how='right')
    • C. pd.merge(sales, returns, on='transaction_id', how='left')
    • D. pd.merge(sales, returns, on='transaction_id', how='outer')
  5. Q5. A customer transaction column 'transaction_date' is stored as object strings '2023-05-12 14:30:00'. What is the correct way to convert it and extract the day of the week name?

    • A. df['transaction_date'].astype('datetime').weekday_name()
    • B. pd.DatetimeIndex(df['transaction_date']).get_day()
    • C. df['transaction_date'].apply(lambda x: x.day_name())
    • D. pd.to_datetime(df['transaction_date']).dt.day_name()
  6. Q6. You execute df.groupby('department').agg({'salary': ['mean', 'std']}). What index structure does the resulting DataFrame column index have?

    • A. Flat Index
    • B. DatetimeIndex
    • C. RangeIndex
    • D. MultiIndex (Hierarchical Column Index)
  7. Q7. While cleaning string data in Pandas, df.drop_duplicates(subset=['email']) fails to remove duplicates that look identical. What is the most common hidden cause?

    • A. The inplace=True parameter was omitted during function call
    • B. drop_duplicates only works on numerical data types
    • C. Inconsistent leading or trailing whitespace in text entries
    • D. Pandas cannot drop duplicate string values across multiple CPU cores
  8. Q8. You wish to transform a wide dataset containing columns ['user_id', 'Q1_sales', 'Q2_sales', 'Q3_sales'] into a long dataset with columns ['user_id', 'Quarter', 'Sales']. Which Pandas method is designed for this?

    • A. pd.pivot()
    • B. pd.concat()
    • C. pd.melt()
    • D. pd.crosstab()
Data Science Practice Questions & Answers | Exam Clue