pandas attribute error : no attribute 'Factor' found

22 次浏览
u63378937

报错:

Traceback (most recent call last):
File "rf.py", line 10, in <module>
    df['species'] = pd.Factor(iris.target, iris.target_names)
AttributeError: module 'pandas' has no attribute 'Factor'


代码:

import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier

iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['is_train'] = np.random.uniform(0, 1, len(df)) <= .75
df['species'] = pd.Factor(iris.target, iris.target_names)


请问这个是什么问题?

2 回答 07-22
lamdba
已采纳

试试把Factor换成Categorical

3 评论 1 07-24
需要登录后才能回答哟~ 点击
相关推荐