【发布时间】:2014-06-12 17:55:59
【问题描述】:
我想知道如何将分箱数据帧转换为可在 sklearn 的 PCA 中使用的分箱 numpy 数组。
这是我目前的代码(x 是我原始的未分箱数据框):
bins=(2,6,10,14,20,26,32,38,44,50,56,62,68,74,80,86,92,98)
binned_data = x.groupby(pd.cut(x.Weight, bins))
我想将 binned_data 转换为 numpy 数组。提前致谢。
编辑:
当我尝试 binned_data.values 时,我收到此错误:
AttributeError: Cannot access attribute 'values' of 'DataFrameGroupBy' objects, try using the 'apply' method
【问题讨论】:
-
是
binned_data.values吗? -
不,我试过了,收到了这个:AttributeError: Cannot access attribute 'values' of 'DataFrameGroupBy' objects, try using the 'apply' method
-
请添加
x的简短描述或一些代码来生成它。
标签: python arrays numpy pandas dataframe