高层级文本特征
在完成清洗和标准化后,您就可以开始从文本数据中创建特征。对于自由文本,最基础的信息就是其规模,例如长度和单词数。在本练习(以及本章其余部分)中,您将专注于上一练习中创建的清洗/转换后的文本列(text_clean)。
本练习是课程的一部分
Python 中的机器学习特征工程
练习说明
- 将每篇演讲的字符长度记录在
char_count列中。 - 将每篇演讲的单词数记录在
word_count列中。 - 将每篇演讲的平均单词长度记录在
avg_word_length列中。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Find the length of each text
speech_df['char_cnt'] = speech_df['text_clean'].____
# Count the number of words in each text
speech_df['word_cnt'] = speech_df['text_clean'].____
# Find the average length of word
speech_df['avg_word_length'] = ____ / ____
# Print the first 5 rows of these columns
print(speech_df[['text_clean', 'char_cnt', 'word_cnt', 'avg_word_length']])