pandas attribute error : no attribute 'Factor' found

_mac 提问于 2个月前

报错:

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)


请问这个是什么问题?

回答 1
1 个回答
1个月前

试试把Factor换成Categorical

回复 · 1
_mac 回复 lamdba 1个月前 回复
改成Categorial,然后看注释再用.from_codes()就行了,弄了大半天!感谢!
需要登录后才能回答,快点击 来分享你的回答吧~
相关推荐
0 关注
0 收藏,43 浏览
邀请回答
分享到