0
0
Pandasdata~15 mins

str.replace() for substitution in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Using str.replace() in pandas for Substitution
📖 Scenario: You work in a company that collects customer feedback. Some feedback entries contain typos or inconsistent words that need correction before analysis.
🎯 Goal: You will create a pandas DataFrame with customer feedback, set up a word to replace, use str.replace() to fix the feedback, and print the corrected feedback.
📋 What You'll Learn
Create a pandas DataFrame with a column named feedback containing exact text entries.
Create a variable old_word with the exact word to replace.
Use str.replace() on the feedback column to replace old_word with a new word.
Print the updated feedback column.
💡 Why This Matters
🌍 Real World
Cleaning and correcting text data is common in customer feedback analysis, social media monitoring, and survey data preparation.
💼 Career
Data scientists and analysts often need to preprocess text data by fixing typos or standardizing terms before running analysis or machine learning.
Progress0 / 4 steps
1
Create the customer feedback DataFrame
Import pandas as pd and create a DataFrame called df with one column named feedback containing these exact entries: 'The product is gud', 'Service was excelent', 'Delivery was fast'.
Pandas
Need a hint?

Use pd.DataFrame() with a dictionary where the key is 'feedback' and the value is a list of the exact strings.

2
Set the word to replace
Create a variable called old_word and set it to the exact string 'gud'.
Pandas
Need a hint?

Just assign the string 'gud' to the variable old_word.

3
Replace the old word with the correct word
Use str.replace() on the feedback column of df to replace old_word with 'good'. Save the result back to the feedback column.
Pandas
Need a hint?

Use df['feedback'].str.replace(old_word, 'good') and assign it back to df['feedback'].

4
Print the updated feedback column
Print the feedback column of df to see the corrected feedback.
Pandas
Need a hint?

Use print(df['feedback']) to display the updated column.