【发布时间】:2019-07-31 21:33:08
【问题描述】:
我有一个具有 4 个特征的数据框。
df
A|B|C|D
green|big|1.3|4
现在,我将所有对象特征(A 和 B)放入一个新的数据框:
df1=df.select_dtypes(include=['object']).columns
df1.dtype
Out: type('O')
最后一步是将 df1 输入一个函数,以确定每个分类特征的唯一值。
for feature in df1.columns:
uniq = np.unique(df1[feature])
print('{}: {} distinct values - {}'.format(feature,len(uniq),uniq))
错误我得到的是:
AttributeError: 'Index' object has no attribute 'columns' when I want to get this:
预期输出:
A: 2 distinct values - ['green' 'blue']
B: 1 distinct values - ['big]
【问题讨论】:
-
你应该看看
unique -
您已经将
df1设置为列。