0
0
Pandasdata~15 mins

Handling inconsistent values in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Handling inconsistent values in pandas
📖 Scenario: You work in a company that collects customer feedback. The feedback data has inconsistent values for the rating column, such as different spellings and cases for the same rating.Cleaning this data will help the company analyze customer satisfaction accurately.
🎯 Goal: You will clean the rating column in a pandas DataFrame by replacing inconsistent values with consistent ones.
📋 What You'll Learn
Create a pandas DataFrame with given customer feedback data
Create a dictionary to map inconsistent ratings to consistent ratings
Use the replace() method with the mapping dictionary to clean the ratings
Print the cleaned DataFrame
💡 Why This Matters
🌍 Real World
Data collected from customers often has inconsistent text entries. Cleaning these values helps in accurate analysis and reporting.
💼 Career
Data scientists and analysts frequently clean and preprocess data to prepare it for analysis, making this skill essential in many data-related jobs.
Progress0 / 4 steps
1
Create the initial DataFrame
Create a pandas DataFrame called feedback with these exact columns and values:
customer_id: [101, 102, 103, 104, 105]
rating: ['Good', 'good', 'Excellent', 'excellent', 'Bad']
Pandas
Need a hint?

Use pd.DataFrame() with a dictionary of lists for columns.

2
Create a mapping dictionary for ratings
Create a dictionary called rating_map that maps these inconsistent ratings to consistent ones:
'good' to 'Good',
'excellent' to 'Excellent',
and keep 'Bad' as is (no mapping needed for 'Bad').
Pandas
Need a hint?

Use a dictionary with keys as inconsistent values and values as correct ones.

3
Replace inconsistent ratings using the mapping
Use the replace() method on the rating column of feedback with the rating_map dictionary to fix inconsistent values. Assign the result back to the rating column.
Pandas
Need a hint?

Use feedback['rating'].replace(rating_map) and assign it back to feedback['rating'].

4
Print the cleaned DataFrame
Print the feedback DataFrame to see the cleaned ratings.
Pandas
Need a hint?

Use print(feedback) to display the DataFrame.