我创建了一个名为"x"的数据框。
我想要创建另一个数据框"y",其中包含数据框"x"中特征"wheat_type"的值。
所以我执行了以下代码:
y=X.loc[:, 'wheat_type']
当我执行以下命令时:
y['wheat_type'] = y.wheat_type("category").cat.codes
我遇到了以下错误
'Series' 对象没有属性 'wheat_type'
在执行 type(X) 后,我得到了
<class 'pandas.core.frame.DataFrame'>
执行type(y)后,我得到了:
<class 'pandas.core.series.Series'>
有没有可能将y转换为数据框?如果不行,请告诉我如何从x创建所需的数据框y。
()
-print df.dtypes
- jezraeldtypes
。 - jezrael