【发布时间】:2017-01-13 00:26:41
【问题描述】:
我正在尝试将数据框转换为字典:
xtest_cat = xtest_cat.T.to_dict().values()
但它会发出警告:
警告:DataFrame 列不是唯一的,python 会省略某些列
我检查了数据框(xtest_cat)的列名:
len(list(xtest_cat.columns.values))
len(set(list(xtest_cat.columns.values)))
它们都是独一无二的。 谁能帮我吗 ?
【问题讨论】:
-
您调用了转置,所以您的索引是唯一的吗?
xtest_cat.T返回转置,使索引成为列 -
@EdChum。是的,我还通过以下方式进行了检查:
print len(xtrain_test.ix[:,0]) print len(list(xtrain_test.ix[:,0])) print len(set(list(xtrain_test.ix[:,0]))) -
您需要通过
print (xtest_cat.index.is_unique)检查索引的唯一性 -
@jezrael 我通过以下
print len(xtrain_test.ix[:,0]) print len(list(xtrain_test.ix[:,0])) print len(set(list(xtrain_test.ix[:,0])))进行了检查。是一样的吗? -
不是,因为它测试第一列,而不是索引。
标签: python pandas dictionary dataframe multiple-columns