Bird
Raised Fist0
Data Analysis Pythondata~20 mins

Survey data analysis pattern in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Survey Data Analysis Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ data_output
intermediate
2:00remaining
Calculate the average satisfaction score by gender

You have a survey dataset with columns Gender and Satisfaction (scale 1-5). What is the average satisfaction score for each gender?

Data Analysis Python
import pandas as pd

data = pd.DataFrame({
    'Gender': ['Male', 'Female', 'Female', 'Male', 'Female'],
    'Satisfaction': [4, 5, 3, 2, 4]
})

result = data.groupby('Gender')['Satisfaction'].mean()
A{'Female': 4.0, 'Male': 3.0}
B{'Female': 4.0, 'Male': 3.5}
C{'Female': 4.0, 'Male': 2.0}
D{'Female': 4.5, 'Male': 3.0}
Attempts:
2 left
💡 Hint

Use groupby on Gender and then calculate the mean of Satisfaction.

🧠 Conceptual
intermediate
1:30remaining
Identify the correct interpretation of a Likert scale distribution

A survey question uses a 5-point Likert scale (1=Strongly Disagree to 5=Strongly Agree). The distribution of responses is skewed towards 5. What does this indicate?

AResponses are evenly spread across all options.
BMost respondents strongly disagree with the statement.
CMost respondents strongly agree with the statement.
DMost respondents chose the neutral option.
Attempts:
2 left
💡 Hint

Think about what a skew towards 5 means on a 1 to 5 scale.

🔧 Debug
advanced
2:00remaining
Fix the error in filtering survey data by age group

The code below tries to filter respondents aged 30 or older but raises an error. Identify the cause.

Data Analysis Python
import pandas as pd

data = pd.DataFrame({'Age': [25, 30, 35, 40]})

filtered = data[data['Age'] >= 30]
ASyntaxError due to incorrect bracket placement in the filter condition.
BKeyError because 'Age' column does not exist.
CTypeError because comparison is done between string and int.
DNo error; code runs correctly.
Attempts:
2 left
💡 Hint

Check how the condition inside the brackets is written.

❓ visualization
advanced
1:30remaining
Choose the correct plot to show satisfaction distribution by department

You want to visualize how satisfaction scores vary across different departments in a survey. Which plot type is best?

AScatter plot of satisfaction vs. age for all respondents.
BLine plot connecting average satisfaction scores over time.
CPie chart showing percentage of respondents per department.
DBox plot showing satisfaction score distribution per department.
Attempts:
2 left
💡 Hint

Think about showing distribution and comparison across categories.

🚀 Application
expert
1:30remaining
Calculate the response rate from survey data

You have a dataset with 1000 invited participants. The survey data contains 750 rows of responses. How do you calculate the response rate?

AResponse rate = 750 - 1000 = -250
BResponse rate = (750 / 1000) * 100 = 75%
CResponse rate = (1000 / 750) * 100 = 133.33%
DResponse rate = 1000 + 750 = 1750
Attempts:
2 left
💡 Hint

Response rate is the percentage of invited participants who responded.

Practice

(1/5)
1. What does the value_counts() function do when analyzing survey data in Python?
easy
A. Calculates the average of numerical answers
B. Groups data by categories for comparison
C. Counts how many times each unique answer appears
D. Removes missing values from the dataset

Solution

  1. Step 1: Understand the purpose of value_counts()

    This function counts the frequency of each unique value in a column, showing how many times each answer appears.
  2. Step 2: Compare with other functions

    Calculating averages is done by mean(), grouping is done by groupby(), and removing missing values uses dropna().
  3. Final Answer:

    Counts how many times each unique answer appears -> Option C
  4. Quick Check:

    value_counts() = count unique answers [OK]
Hint: Remember: value_counts counts answers, not averages [OK]
Common Mistakes:
  • Confusing value_counts with mean()
  • Thinking value_counts groups data
  • Assuming it removes missing data
2. Which of the following is the correct syntax to get the average rating from a survey column named rating in a pandas DataFrame df?
easy
A. df['rating'].mean()
B. df['rating'].count()
C. df.groupby('rating').sum()
D. df['rating'].value_counts()

Solution

  1. Step 1: Identify the function for average calculation

    The mean() function calculates the average of numerical values in a column.
  2. Step 2: Check other options

    count() counts non-missing values, groupby().sum() sums grouped data, and value_counts() counts unique values.
  3. Final Answer:

    df['rating'].mean() -> Option A
  4. Quick Check:

    Average = mean() [OK]
Hint: Use mean() to get average of numeric columns [OK]
Common Mistakes:
  • Using count() instead of mean()
  • Confusing value_counts() with average
  • Trying to sum without grouping
3. Given the following code, what will be the output?
import pandas as pd
data = {'gender': ['M', 'F', 'F', 'M', 'F'], 'score': [5, 3, 4, 2, 5]}
df = pd.DataFrame(data)
result = df.groupby('gender')['score'].mean()
print(result)
medium
A. gender F 3.5 M 4.0 Name: score, dtype: float64
B. gender F 4.0 M 3.5 Name: score, dtype: float64
C. gender M 4.0 F 3.5 Name: score, dtype: float64
D. gender F 3.0 M 4.0 Name: score, dtype: float64

Solution

  1. Step 1: Group scores by gender

    Group 'score' values by 'gender': For 'F' scores are [3,4,5], for 'M' scores are [5,2].
  2. Step 2: Calculate mean for each group

    Mean for 'F' = (3+4+5)/3 = 4.0; Mean for 'M' = (5+2)/2 = 3.5.
  3. Final Answer:

    gender F 4.0 M 3.5 Name: score, dtype: float64 -> Option B
  4. Quick Check:

    Group mean = correct averages [OK]
Hint: Calculate group means by averaging grouped values [OK]
Common Mistakes:
  • Mixing up group labels and values
  • Calculating sums instead of means
  • Ignoring group sizes
4. The following code is intended to count how many times each answer appears in the 'response' column, but it raises an error. What is the error and how to fix it?
import pandas as pd
df = pd.DataFrame({'response': ['Yes', 'No', 'Yes', 'Maybe']})
counts = df.response.value_count()
print(counts)
medium
A. KeyError because 'response' column does not exist
B. SyntaxError due to missing parentheses in print statement
C. TypeError because value_count() requires an argument
D. AttributeError because the method name should be value_counts()

Solution

  1. Step 1: Identify the method name error

    The method value_count() is incorrect; the correct method is value_counts() with an 's' at the end.
  2. Step 2: Correct the method name

    Changing value_count() to value_counts() fixes the AttributeError and allows counting unique values.
  3. Final Answer:

    AttributeError because the method name should be value_counts() -> Option D
  4. Quick Check:

    Correct method is value_counts() [OK]
Hint: Remember the method ends with 's': value_counts() [OK]
Common Mistakes:
  • Misspelling method name without 's'
  • Confusing print syntax errors
  • Assuming column name is missing
5. You have a survey DataFrame df with columns age_group and satisfaction_score. How would you calculate the average satisfaction score for each age group and then find which age group has the highest average score?
hard
A. Use df.groupby('age_group')['satisfaction_score'].mean().idxmax()
B. Use df['satisfaction_score'].max() directly
C. Use df.value_counts('age_group') and pick max
D. Use df.groupby('satisfaction_score')['age_group'].mean()

Solution

  1. Step 1: Group by age group and calculate average satisfaction

    Use groupby('age_group')['satisfaction_score'].mean() to get average scores per group.
  2. Step 2: Find the age group with the highest average

    Use idxmax() on the resulting Series to get the group label with the highest average score.
  3. Final Answer:

    Use df.groupby('age_group')['satisfaction_score'].mean().idxmax() -> Option A
  4. Quick Check:

    Group mean + idxmax() finds highest average [OK]
Hint: Chain mean() and idxmax() to find top group quickly [OK]
Common Mistakes:
  • Using max() on scores without grouping
  • Confusing value_counts() with averages
  • Grouping by wrong column
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