拆分数值型与分类型列
在上一个练习中,您已经了解了数据集的特征,现在可以开始做一些数据预处理。接下来,您将从 telco_raw DataFrame 中分离出分类型变量和数值型变量,并自定义区分分类型与数值型的唯一值计数阈值。pandas 模块已作为 pd 为您导入。
电信流失原始数据集 telco_raw 已作为 pandas 的 DataFrame 为您加载。您可以在控制台中先探索数据集以熟悉其结构。
本练习是课程的一部分
Python 营销中的机器学习
练习说明
- 存储
customerID和Churn的列名。 - 将唯一值个数少于 5 的列名赋给
categorical。 - 从该列表中移除
target。 - 将不在
custid、target和categorical中的所有列名赋给numerical。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Store customerID and Churn column names
custid = ['___']
target = ['___']
# Store categorical column names
categorical = telco_raw.___()[telco_raw.nunique() < ___].keys().tolist()
# Remove target from the list of categorical variables
categorical.remove(___[0])
# Store numerical column names
numerical = [x for x in telco_raw.___ if x not in custid + ___ + categorical]