Solution Explanations: Text Feature Engineering
Review solution explanations for the code challenges on text feature engineering.
We'll cover the following...
Solution 1: Feature construction
Here’s the solution:
Press + to interact
main.py
feedback.csv
import pandas as pdfeedback_df = pd.read_csv('feedback.csv')feedback_df['feedback_length_chars'] = feedback_df['feedback'].apply(lambda x: len(x))feedback_df['feedback_length_words'] = feedback_df['feedback'].apply(lambda x: len(x.split()))print(feedback_df['feedback_length_chars'])print(feedback_df['feedback_length_words'])
Let’s go through the solution explanation:
Line 4: We create a new column named
feedback_length_chars
using theapply()
function on thefeedback
column. For each text in the ...
Access this course and 1400+ top-rated courses and projects.