satisfaction_level last_evaluation number_project average_montly_hours time_spend_company Work_accident left promotion_last_5years dept salary
0.38 0.53 2 157 3 0 1 0 TECHNICAL low
0.8 0.86 5 262 6 0 1 0 HR medium
0.11 0.88 7 272 4 0 1 0 HR medium
0.72 0.87 5 223 5 0 1 0 FINANCE low
0.37 0.52 2 159 3 0 1 0 MARKETING low
0.41 0.5 2 153 3 0 1 0 TECHNICAL low
0.1 0.77 6 247 4 0 1 0 HR low
0.92 0.85 5 259 5 0 1 0 FINANCE low
0.89 1 5 224 5 0 1 0 HR low
我使用了上述数据并尝试使用 DictVectorizer 转换 C。代码如下
import pandas as pd
from sklearn.feature_extraction import DictVectorizer
dv=DictVectorizer()
hr_data=pd.read_csv(r"C:\Users\IBM_ADMIN\Desktop\data\HR_comma_sep.csv")
dv.fit_transform(X=hr_data.dept)
但它抛出了错误:
“str”对象没有属性“items”